Trouble Animating Sprites
Blitz3D Forums/Blitz3D Beginners Area/Trouble Animating Sprites
| ||
| Hey everyone, I just purchased BlitzPro3D a few hours ago and I'm lovin' it. Right now I'm trying to do some 2D animation and I'm having some trouble. I'm able to have it loop the correct animation when the left and right arrow keys are being pressed, but I also want to add a "standing" animation. I've sort of got it working, but the way I've coded it makes you see a quick flip of animation as it does the calculations for finding the right frame on the animation strip. Here's the code and the two image filmstrips that I'm using. Zip File (113kb)
Global elite, eliteframe=0, eliteframestand=0, tmrelite, dir=0, stand_dir=0
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 Not KeyDown(205) And dir = 0 Then
timing_elite_stand()
DrawImage elite_stand,elite_x,elite_y,eliteframestand
EndIf
If Not KeyDown(203) And dir = 6 Then
timing_elite_stand()
DrawImage elite_stand,elite_x,elite_y,eliteframestand
EndIf
If KeyDown(205) Then
dir=0
timing_elite()
elite_x = elite_x + elite_sp
DrawImage elite,elite_x,elite_y,eliteframe
EndIf
If KeyDown(203) Then
dir=6
timing_elite()
elite_x = elite_x - elite_sp
DrawImage elite,elite_x,elite_y,eliteframe
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() > tmrelite + 120 Then
tmrelite=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
I'm not sure how else to code it. Any help would be great, thanks! -Alex |
| ||
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 |
| ||
| My goodness! Genius! I forgot that you could do more than one if statement in a huge if clock. Thanks a whole bunch! |