Animation won't work

BlitzPlus Forums/BlitzPlus Programming/Animation won't work

D2(Posted 2007) [#1]
I'm trying to animate a ship for my scrolling shooter, but when I run it, all it does is sit there on frame 0.

Here's the LoadAnimImage section I used
;load the ship image
playerImage = LoadAnimImage("ship_idle.bmp",80,70,0,4)


Everything looks fine. Here's the 1st portion of the main loop, concerned with animation.
While Not KeyHit(KEY_ESC)

;clear screen
Cls

;animate the ship
player1\frame = player1\frame + 1
If player1\frame > 4
	player1\frame = 0
EndIf 	


I think maybe here is where I'm screwing up?


Matty(Posted 2007) [#2]
graphics 800,600,0,2
playerImage=loadanimImage("ship_idle.bmp",80,70,0,4)
type UnitObject ;just some name for your type so that this code snippet works

field frame
field image
end type
player1.unitobject=new unitobject
player1\image=playerimage
player1\frame=0
repeat


cls
player1\frame=(player1\frame +1) mod 4 ;frames go from 0-3, meaning there are 4 frames in total with the first being frame 0 and the last being frame 3
drawimage player1\image,400,300,player1\frame

flip

until keydown(1)
freeimage playerImage
delete each unitobject
end




should get you started.


D2(Posted 2007) [#3]
Funny thing happened. I cut and pasted into Blitz Basic (which I have the trial of) and ran it. It worked perfectly. Then I cut and pasted back into BlitzPlus, ran it, and it also worked great. Why?


Matty(Posted 2007) [#4]
Blitzbasic and blitzplus are fairly interchangeable, there are differences but simple code like that above will work in all 3 of blitz3d, blitzplus and blitzbasic. Don't know about blitzmax.