Animation 2

Blitz3D Forums/Blitz3D Beginners Area/Animation 2

po(Posted 2004) [#1]
I have sort of got the idea of how animation works now(thanks to DjBigWorm and others). I am having another problem:


I want to make the man go both ways, I can, but the image strip of the man walking left isn't working, how do I make it work?
Here is my man(just save picture as):

I know it looks like he is doing jumping jacks rather then walking :)


semar(Posted 2004) [#2]
Your sprite animation is made up by 8 frames: 0-3 for walking right, 4-7 for walking left.

In your code, you use always the frame for right walking, in fact the statement used to change the frames is:
frmman=( frmman + 1 ) Mod 4


The above statement makes the values for frmman going from 0 to 3.

If you want to use also the frames for left animation, you should add 4 to the calculated frame, so that it goes from 4 to 7.
frmman=( frmman + 1 ) Mod 4 ;0 <---> 3
frmman = frmman + 4 ; 0+4 <---> 3+4


Of course, you have to decide when to use the left frames, and when to use the right ones.

In your code, you can easily achieve that, if you use the direction variable 'dir', which is set to 1 for going right, and -1 for going left. So you could do so:
[EDITED]
Global frame ;put this in your variable declaration
.
.

frame=( frame + 1 ) Mod 4
if dir = -1 then
frmman = frame + 4
else
frmman = frame
endif


Hope this has sense for you,
Sergio.


Valgar(Posted 2004) [#3]
If i dremember well in the loadanimimage command you must set a frame number and first frame.
But i have tried to set 5 as the first and don't work....for what i know image strip are counted from left to right and from up to down....but it seems that from frame 5 to 8 don't work....maybe there's something wrong with the image?


Valgar(Posted 2004) [#4]
I have tried the modify but i think that all you get is an "image frame out of range"
Strange.


semar(Posted 2004) [#5]
Snippet updated. Does it work now ?

Sergio.


Valgar(Posted 2004) [#6]
I think no.
It continue to display right frames.
(it's a simple code but i think there's something wrong...)


po(Posted 2004) [#7]
Hmmmm... Semar, your code does not seem to work, it just stays as the first frame.


big10p(Posted 2004) [#8]
As Semar said, your frmman variable only cycles through the values 0 to 3. Try this:

Global man, frmman=0, tmrman, dir=0

Graphics 800,600

SetBuffer BackBuffer()

man=LoadAnimImage("walkingman.jpg",40,40,0,8)

MaskImage man,255,255,255

manx=0
many=280
mansp=2

While Not KeyHit(1)

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

If KeyDown(205) Then
	
	dir=0

	timing_man()
	
	manx = manx + mansp
	
EndIf 

If KeyDown(203) Then
	
	dir=4

	timing_man()
	
	manx = manx + -mansp
	
EndIf
 
DrawImage man,manx,many,frmman

Flip
Cls

Wend

End

;FUNCTIONS;;;;;;

Function timing_man()

If MilliSecs() > tmrman + 100 Then
	
		tmrman=MilliSecs()
		frmman=((frmman + 1) Mod 4) + dir
		
End If

End Function



Think your left anim images need fixing because he seems to jerk forward when walking left. ;)


po(Posted 2004) [#9]
That works, I have fixed the image problem, thanks!


big10p(Posted 2004) [#10]
np. ;)

...this is no big deal but you may want to change the line:

manx = manx + -mansp


to:

manx = manx - mansp


Not sure what I was thinking of there. :P