Man, BlitzMax is a LOT harder than Blitz3D! :p
I get the compile error "identifier hero not found." I thought that the "Global t:Timage=LoadImage( t )" line in InitializeSprites() would create a global image named hero from the file sprites/hero.png, but it doesn't seem to be working. Actually, I'm not even sure if variables in Blitz are meant to be mangled in this way. I'm coming fresh out of learning Flash AS, so if this business of dynamically naming variables is insane, tell me. On the other hand, if you can think of a way to make it work, please do explain it to me.
Basically, I'd like to create a sprite type, subtype it into variaout other types of entities that have more variables, and treat the graphic tied to any one instance of the type as just another arbitrary vriable that can be set and changed on the fly during runtime. The uncompilable code above is one way of attempting it.
As you can tell, I really don't have a firm grasp of BlitzMax yet. You can link me to tutorials all day, but I won't really "get it" until I see working solutions to visual problems. Abstract examples don't usually illustrate enough to me. I need to see what works and what doesn't, and when something doesn't work, I need to be able to post my erroneous code and ask WHY it didn't work. Only after several such explainations, I'm afraid, will I start to genuinely understand Blitz's syntax and the proper way to use these commands.
Thanks, in advance, to anyone who helps me through this burn-in phase.
Strict Include "DeltaTime.bmx" Include "FPS.bmx" Global ScreenWidth=800 Global ScreenHeight=600 Graphics ScreenWidth,ScreenHeight,0 InitializeSprites() Delta.Start() Type Sprite Field x:Float, y:Float, image:TImage Method Draw() DrawImage(image,x,y) End Method End Type Type Actor Extends Sprite Field xVel:Float, yVel:Float, rot:Float, rotDelta: Float Field health:Float, maxHealth:Float Method Spawn() health = maxHealth End Method Method Update() x:+ xVel y:+ yVel rot:+ rotDelta End Method End Type Type PlayerObject Extends Actor Method GetInputs() If KeyDown(KEY_LEFT) xvel:-1 If KeyDown(KEY_RIGHT) xvel:+1 If KeyDown(KEY_UP) yvel:-1 If KeyDown(KEY_DOWN) yvel:+1 End Method End Type Function InitializeSprites() Local arr:String[]=["hero"] For Local t:String=EachIn arr t="sprites/"+t+".png" Print "loading "+ t Global t:Timage=LoadImage( t ) Next End Function Global Player:PlayerObject=New PlayerObject Player.image=hero Player.x=ScreenWidth/2 Player.y=ScreenHeight/2 Player.xVel=0 Player.yVel=0 Repeat Cls Delta.Update() FPS.Display() player.draw Flip Until KeyDown(Key_Escape)
I get the compile error "identifier hero not found." I thought that the "Global t:Timage=LoadImage( t )" line in InitializeSprites() would create a global image named hero from the file sprites/hero.png, but it doesn't seem to be working. Actually, I'm not even sure if variables in Blitz are meant to be mangled in this way. I'm coming fresh out of learning Flash AS, so if this business of dynamically naming variables is insane, tell me. On the other hand, if you can think of a way to make it work, please do explain it to me.
Basically, I'd like to create a sprite type, subtype it into variaout other types of entities that have more variables, and treat the graphic tied to any one instance of the type as just another arbitrary vriable that can be set and changed on the fly during runtime. The uncompilable code above is one way of attempting it.
As you can tell, I really don't have a firm grasp of BlitzMax yet. You can link me to tutorials all day, but I won't really "get it" until I see working solutions to visual problems. Abstract examples don't usually illustrate enough to me. I need to see what works and what doesn't, and when something doesn't work, I need to be able to post my erroneous code and ask WHY it didn't work. Only after several such explainations, I'm afraid, will I start to genuinely understand Blitz's syntax and the proper way to use these commands.
Thanks, in advance, to anyone who helps me through this burn-in phase.