Trouble Animating Sprites

Blitz3D Forums/Blitz3D Beginners Area/Trouble Animating Sprites

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Phew that took a while to figure out how you were doing that, however I've sussed it (code below). The biggest problem is that you were using the same variable for your timing for both moving and standing still. Seperating this into two timer vars makes it work. I also tightened up the main loop a bit before I figured it out but I've left it changed for you :)

Global elite, eliteframe=0, eliteframestand=0, tmrelite, dir=0, stand_dir=0,tmrelites

Graphics 640,480

SetBuffer BackBuffer()

elite=LoadAnimImage("elite.jpg",240,201,0,12)
elite_stand=LoadAnimImage("elite_standing.jpg",240,201,0,8)

MaskImage elite,255,255,2
MaskImage elite_stand,255,255,2

elite_x=0
elite_y=240
elite_sp=3

While Not KeyHit(1)

Color 255,255,255
Rect 0,0,800,600,1

If KeyDown(205) Then	
	dir=0
	timing_elite()	
	elite_x = elite_x + elite_sp	
	DrawImage elite,elite_x,elite_y,eliteframe	
ElseIf KeyDown(203) Then	
	dir=6
	timing_elite()	
	elite_x = elite_x - elite_sp	
	DrawImage elite,elite_x,elite_y,eliteframe	
Else
	timing_elite_stand()
	DrawImage elite_stand,elite_x,elite_y,eliteframestand
EndIf

;	DrawImage elite,elite_x,elite_y,eliteframe
 

Flip
Cls

Wend

End

; functions - controlling the timing
Function timing_elite()
If MilliSecs() > tmrelite + 100 Then	
		tmrelite=MilliSecs()
		eliteframe=((eliteframe + 1) Mod 6) + dir		
End If
End Function

Function timing_elite_stand()
If MilliSecs() > tmrelites + 120 Then
	tmrelites=MilliSecs()
	
	If dir = 6 Then
		stand_dir = 4
	Else
		stand_dir = 0
	End If
	
	eliteframestand=((eliteframestand + 1) Mod 4) + stand_dir
End If
End Function