Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Hotshot on December 17, 2009
-
need to work on tree and clouds
-
I cant seem get the tree right!
(http://www3.picturepush.com/photo/a/2659596/img/Anonymous/Untitled.png)
' Shadow of the Beast Demo :)
SuperStrict
Graphics 640,480,0
Global T_list:TList = New TList
Global Background1:TImage=LoadImage("media\bgd1_ciel.png")
Global Background2:TImage=LoadImage("media\bgd2_montagnes.PNG")
Global Background3:TImage=LoadImage("media\bgd3_sol1.png")
Global Background4:TImage=LoadImage("media\bgd4_sol2.png")
Global Background5:TImage=LoadImage("media\bgd5_sol3.png")
Global Background6:TImage=LoadImage("media\sprite_barriere.bmp")
' Put the Clouds in the sky
Global Cloud1:TImage=LoadImage("media\sprite_nuages1.bmp")
Global Cloud2:TImage=LoadImage("media\sprite_nuages2.bmp")
Global Cloud3:TImage=LoadImage("media\sprite_nuages3.bmp")
Global Cloud4:TImage=LoadImage("media\sprite_nuages4.bmp")
Global Tree :TImage=LoadImage("media\sprite_arbre.png")
Type TBackground
Field x: Int , y:Int
Field x1:Int, y1:Int
Field x2:Int, y2:Int
Field x3:Int, y3:Int
Field x4:Int, y4:Int
Field x5:Int, y5:Int
Field x6:Int, y6:Int
Field c:Int,c2:Int,c3:Int,c4:Int
Field t:Int
Method Draw()
SetViewport 0,0,GraphicsWidth(),background1.height
TileImage Background1,x,0
DrawImage Cloud1,c+GraphicsWidth(),0
DrawImage Cloud2,c2+GraphicsWidth(),10
DrawImage Cloud3,c3+GraphicsWidth(),20
DrawImage Cloud4,c4+GraphicsWidth(),30
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
DrawImage Tree,200+t,95
SetViewport 0,370,GraphicsWidth(),background3.height
TileImage Background3,x3,370
SetViewport 0,380,GraphicsWidth(),background4.height
TileImage Background4,x4,380
SetViewport 0,400,GraphicsWidth(),background5.height
TileImage Background5,x5,400
SetViewport 0,390,GraphicsWidth(),background6.height
TileImage Background6,x6,390
x =(x-1 ) Mod background1.width
x2=(x2-1.5) Mod background2.width
x3=(x3-2) Mod background3.width
x4=(x4-3) Mod background4.width
x5=(x5-5) Mod background5.width
x6=(x6-6) Mod background6.width
c=(c-3)
c2=(c2-2)
c3=(c3-1)
c4=(c4-1)
t=(t-3)
' Does the background come off the screen? if yes then
' Repeat!
If c=<-1500
c=800
EndIf
If c2=<-1500
c2=800
EndIf
If c3=<-1500
c3=800
EndIf
If c4=<-1500
c4=800
EndIf
If t=<-2000
t=800
EndIf
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
EndMethod
End Type
Local T:Tbackground=New Tbackground
Repeat
Cls
T.Draw
Flip
Until MouseHit(1)
-
Why do you need setting viewport for each draw image?
I believe your problem is here:
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
DrawImage Tree,200+t,95This viewport command is clipping the tree image.
-
Why do you need setting viewport for each draw image?
The reason why I did that because I didnt want tilesimage to overlap each other if that make sense.
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
DrawImage Tree,200+t,95This viewport command is clipping the tree image.
I think if I remove the viewport then it will show the whole tree...but it still cause image probelm if i remove the viewport
-
Try to reset your viewport to the default before drawing the tree:
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
DrawImage Tree,200+t,95
-
Thank you rbz and working fine now :)
one problem....the music file i have is MOD and i am sure blitmax have FMOD library to able put music mod on.
-
When I run the program and I got the sound working.
when I got the demo up and running....it doesnt show the graphics on the screen but music is on
it say Unhandled exception: Attempt to access field or method of null object
I also add the code and exe files in the attachments
' Shadow of the Beast Demo :)
SuperStrict
Rem
v0.53 fixed the filelist so that only the actual song being played is highlighted regardless of changing folders
v0.52 fixed the filelist so that it only shows folders and actual modfiles
v0.51 first release
EndRem
Framework BRL.GLMax2D
Import aln.bass
SetGraphicsDriver GLMax2DDriver()
AppTitle="Alan BASS module test"
' GLOBALS
Global musicmodule:TBassmod = New TBassmod
musicmodule.Load("media\b-title.mod", 0 )
musicmodule.Play()
Graphics 640,480,0
Global T_list:TList = New TList
Global Background1:TImage=LoadImage("media\bgd1_ciel.png")
Global Background2:TImage=LoadImage("media\bgd2_montagnes.PNG")
Global Background3:TImage=LoadImage("media\bgd3_sol1.png")
Global Background4:TImage=LoadImage("media\bgd4_sol2.png")
Global Background5:TImage=LoadImage("media\bgd5_sol3.png")
Global Background6:TImage=LoadImage("media\sprite_barriere.bmp")
' Put the Clouds in the sky
Global Cloud1:TImage=LoadImage("media\sprite_nuages1.bmp")
Global Cloud2:TImage=LoadImage("media\sprite_nuages2.bmp")
Global Cloud3:TImage=LoadImage("media\sprite_nuages3.bmp")
Global Cloud4:TImage=LoadImage("media\sprite_nuages4.bmp")
Global Tree :TImage=LoadImage("media\sprite_arbre.png")
Type TBackground
Field x: Int , y:Int
Field x1:Int, y1:Int
Field x2:Int, y2:Int
Field x3:Int, y3:Int
Field x4:Int, y4:Int
Field x5:Int, y5:Int
Field x6:Int, y6:Int
Field c:Int,c2:Int,c3:Int,c4:Int
Field t:Int
Method Draw()
SetViewport 0,0,GraphicsWidth(),background1.height ' WHY IT IS ERROR?
TileImage Background1,x,0
DrawImage Cloud1,c+GraphicsWidth(),0
DrawImage Cloud2,c2+GraphicsWidth(),10
DrawImage Cloud3,c3+GraphicsWidth(),20
DrawImage Cloud4,c4+GraphicsWidth(),30
' fixed the tree ! YAY
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
DrawImage Tree,200+t,95
SetViewport 0,370,GraphicsWidth(),background3.height
TileImage Background3,x3,370
SetViewport 0,380,GraphicsWidth(),background4.height
TileImage Background4,x4,380
SetViewport 0,400,GraphicsWidth(),background5.height
TileImage Background5,x5,400
SetViewport 0,390,GraphicsWidth(),background6.height
TileImage Background6,x6,390
x =(x-1 ) Mod background1.width
x2=(x2-1.5) Mod background2.width
x3=(x3-2) Mod background3.width
x4=(x4-3) Mod background4.width
x5=(x5-5) Mod background5.width
x6=(x6-6) Mod background6.width
c=(c-3)
c2=(c2-2)
c3=(c3-1)
c4=(c4-1)
t=(t-3)
' Does the background come off the screen? if yes then
' Repeat!
If c=<-1500
c=800
EndIf
If c2=<-1500
c2=800
EndIf
If c3=<-1500
c3=800
EndIf
If c4=<-1500
c4=800
EndIf
If t=<-2000
t=800
EndIf
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
EndMethod
End Type
Local T:Tbackground=New Tbackground
Repeat
Cls
If AppTerminate() Then
musicmodule.Free()
EndGraphics
End
End If
T.Draw
Flip
Until MouseHit(1)
musicmodule.Free()
EndGraphics()
End
-
had anyone check my demo as i got error saying Unhandled exception: Attempt to access field or method of null object
-
Unhandled exception: Attempt to access field or method of null object
The error you are getting is because the variables are out of scope, and the content has been set to null. Blitzmax comes with built in garbage collection, so it keeps an eye out for variables, types, etc. and if they no longer are refered to, or becomes out of scope, then it clears them out to free up memory.
I am not really sure why you want to use a type for the drawing. It seems like you are overly complicating things. Why not just store the images and x values in an array, or simply variables and then have a regular while/wend loop where you draw them.
Another thing I spotted was that you have a line where you are adding a floating point value to an integer, which makes no sense since .5 will be rounded up to 1.0 anyways.
When running in debug mode, and the code stops, then you can use the right side of the IDE, where it lists various variable states and such. If you take a look there you will find that your images has been cleared to null, which is why they will not show and why the code halts with an error.
I would recomend that you take another approach instead of the whole type thing. Types are really great, but not always the route to go. Sometimes a more simple approach is much better, especially since its not a big complicated project you are working on.
[edit]
Shortly after writing the above, I decided to take a look at your code anyways. And the reason why your images are not shown and the code breaks down is that they are not loaded at all. I am not sure you fully understands the Framework/Import part of the language. What it does is it allows you to pick only the parts of the blitzmax language you want to include into your file. The Framework command lets you pick the main starting library that your project will be build on. The Import command lets you pick any other library that you would want.
In your code, you have only the two lines that was in the test code I made for you. But since my example only had to open a graphics window and load and play a module, I only had those two lines, because that was all I needed to include.
But in this project you have here, you are attempting to load two different kinds of image files. What code should be handling that then? Nothing you have added, so instead it just breaks down. You will have to make sure that you include all code needed, if you want to make use of the Framework/Import command feature.
There is a tool that can help you picking what to use as framework and imports, if you are uncertain. You can get it from this website:
http://homepage.ntlworld.com/config/fa/ (http://homepage.ntlworld.com/config/fa/)
If you add the following imports to your code, then your code should compile and work:
Import BRL.PNGLoader
Import BRL.BMPLoader
-
hiya zawran,
thank you for explaining me about Unhandled exception: Attempt to access field or method of null object and it was good explain on what you have said.
Import BRL.PNGLoader
Import BRL.BMPLoader
That interesting to know :)
thank you very much.
-
Just need uploading to my Website and yep, it`s working lol :)