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.
set display mode 800,600,32
sync on
sync rate 60
REM << load and cut image map into seperate animatable images
load bitmap "alienanim.jpg",1
set current bitmap 1
for t = 1 to 4
inc x2,100
get image t,x1,0,x2,200
inc x1,100
next t
delete bitmap 1
set current bitmap 0
REM << set sprite's initial location and image
frame = 3
sprite 1,x,250,frame
REM <<<<<<<< main loop >>>>>>>>>>
repeat
REM << make character move across screen/animate sprite
if rightkey() = 1
REM << flip sprite image if facing left
if direction = 1
mirror sprite 1
direction = 0
endif
inc x
REM << change sprite image every few loops
frame = animator()
endif
if leftkey() = 1
REM << flip sprite if facing right
if direction = 0
mirror sprite 1
direction = 1
endif
dec x
REM << change sprite image every few loops
frame = animator()
endif
REM << idle frame of animation/here is where you could place an idle animation
if leftkey() = 0 and rightkey() = 0 then frame = 3
REM << update sprite location and frame
sprite 1,x,250,frame
text 0,0,"frame:" + str$(frame)
sync
cls
until mouseclick() = 1
delete sprite 1
end
REM << this function delays the switching of frames
function animator()
inc count1
if count1 = 10
inc frame
count1 = 0
if frame = 5 then frame = 1
endif
endfunction frame
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+