Simple 2d animation info
Blitz3D Forums/Blitz3D Beginners Area/Simple 2d animation info
| ||
| Hi to all. It's a simple problem but don't know how to resolve this. I have an animstrip of 8 frames of a jet that make a rotation. The frame from 0 to 4 is the left rotation,the frame from 5 to 8 is the right rotation. My sprite is moved by joypad. I don't know how to tell my jet that if i hit right he must roll right and when reach the endframe must stop in this position,and if i hit left he must roll left and when reach the endframe must stop. This is the simple answer. The complex answer.... If i want to track the current frame and when i hit left or right the sprite start roll from the position it was until he reach the end of that direction,what can i do to make this? Actually my animstrip is made in this manner: from left to right ^ | -> --> ---> <- <-- <--- i think one of the solution involve change the animstrip in this manner: ^ <--- <-- <- | -> --> ---> Right? Thanks in advance. |
| ||
| roll=roll+1 If roll>8 Then roll=8 Is it more complex than that? |
| ||
| Yes but in this manner if i turn the other direction the animation don't know where it is the current frame and display the wrong frame. Example: turn right if i turn left turn left BUT from the current frame turn left if i turn right turn right BUT from the current frame something like this.... |
| ||
| simply apply an offset equal to the total number of frames/2 depending on the direction they are turning/facing (use a variable to store the direction) if direction=left then offset=0 else offset = (NumFrames/2) *EDIT* An excerpt from a piece of code I wrote a while ago: |
| ||
| incidentally, I wrote a piece of code to flip animation frames, saving you doing it manually. |
| ||
I've made a small example but it seems that the sprite only turn left and don't display the intermediate frames...
width=640
height=480
Graphics width,height,0,1
prova=LoadImage("jet1.bmp")
MidHandle prova
prova2=LoadAnimImage("jet-strip.bmp",43,52,0,4)
MidHandle prova2
Global x=320
Global y=240
While Not KeyHit(1)
assex=JoyX()*2
assey=JoyY()*2
SetBuffer BackBuffer()
Cls
x=x+assex
y=y+assey
If x => 630 Then x=x-2
If x <= 10 Then x=x+2
If JoyX()=1
If MilliSecs() > timer + 100
timer=MilliSecs()
EndIf
current_frame=fotogramma
fotogramma=current_frame+1
If fotogramma = 4 Then fotogramma=4
Else fotogramma=2
EndIf
If JoyX()=-1
If MilliSecs() > timer + 100
timer=MilliSecs()
EndIf
current_frame=fotogramma
fotogramma=current_frame-1
If fotogramma = 0 Then fotogramma=0
Else fotogramma=2
EndIf
DrawImage prova2,x,y,fotogramma
Flip
Wend
|
| ||
| Ok totally sorted the problem and addedd some nice "features" :) Now the sprite roll left & right correctly from the CURRENT frame,and if a joypad isn't pressed for some time the ship reset its position facing up. Thanks for the help. |