Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Animation sprite

Author
Message
Bio Fox
20
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 6th Apr 2005 10:48
I am having trouble figuring out how to make it appear a sprite moves instead of sliding it across the screen. Pretty much like a walking sprite that moves it's arms and legs when it moves left or right but stops when not going left or right.

Here is my code:
sync on
sync rate 40
x=0
y=0
CLS
load image "level1w1.bmp",1
load image "valiantwarrior.bmp",2
Sprite 1,x,y,1
Size Sprite 1,2500,500
Set Sprite 1,1,1
Sprite 2,50,337,2
Size Sprite 2,180,150
Set Sprite 2,1,1
Do
if downkey()=1 then y=y+0
if leftkey()=1 then x=x+3
if rightkey()=1 then x=x-3
Sprite 1,x,y,1
Size Sprite 1,2500,500
Set Sprite 1,1,1
sync
loop

Rook Takes Pawn Productions... "Now if only we could get that accursed bishop!"
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 22nd May 2005 21:10 Edited at: 22nd May 2005 21:15
The Professor,

I notice it's been over a month since you have made this post. However, there have been a few post on this very topic within this forum, which have not been answered. This is strange because it is a rather simple problem. Let's get down to it.

The source is below and the image map I used I have attached to this post. Simply, when either the left or right arrow key is pressed, then a function is ran to animate the sprite. Also, given the arrow pressed, the sprite's x coordinate variable is either increased or decreased. This all makes the character to appear to be walking either way across the screen. Lastly, a direction variable is used to tell the program to mirror the sprite's images if a different direction is pressed then that of the last direction. To specify, if the last key pressed was the right arrow, and the current key press is the left arrow, the program mirrors the sprite's images. This command only needs to be called once per change in direction.



Look at the code above. After the splitting of the image map, I am left with four seperate frames of an animation sequence. In the function, which is called ONLY when the user presses an arrow key, the number of image the sprite will use is increased every ten loops. The sprite call uses the variable frame as the image in which to display when called. To make the animation loop the images, I have placed that if frame goes above the number of available images for this animation(in this case, four) then reset frame to one, the first frame(image) used for animation. Then, the frames are ran back through.

This happens over and over again until the user lets off of both arrow keys. If the user is not pressing either arrow key, as completed in the line if leftkey() = 0 and rightkey() = 0 then frame = 3, the sprite's image is defaulted to the idle frame. In this case, one.


+NanoBrain+

Attachments

Login to view attachments
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 23rd May 2005 08:35
No offense to NanoBrain because he is only trying to help out. Didn't I provided source code for this in another post for you, Professor? I know I didn't spell it out exactly like NanoBrain, but the info is definitely here in the forums.

Login to post a reply

Server time is: 2025-05-18 02:10:28
Your offset time is: 2025-05-18 02:10:28