I'm creating a 2D character sprite which will be controlable with the left and right keys. I'm inexperienced when it comes to 2D coding so it's probably very easy to accomplish what I want. Anyway, I have the sprite set up and I can move the sprite to the left and right directions.
The problem though is that I want a specific frame to play when the character stop moving. Or, to simplify a little:
When leftkey is pressed, move sprite left and play walking animation
When leftkey is released, I want the sprite to change to a standing person, depending on what way the player moved before, the player will face that way.
I have tried using flags, but with no success.
Here is the code so far:
SET DISPLAY MODE 1024, 768, 32
AUTOCAM OFF
HIDE MOUSE
SYNC ON
SYNC RATE 32
CREATE ANIMATED SPRITE 1, "Media\Sprites\Charles_trans.png", 8, 3, 1
SET SPRITE frame 1, 18
runleft_flag as boolean
runright_flag as boolean
standleft_flag as boolean
standright_flag as boolean
px = 400
py = 400
DO
paste sprite 1, px, py
if standleft_flag = 1
SET SPRITE frame 1, 18
endif
if standright_flag = 1
SET SPRITE frame 1, 17
endif
if leftkey()=1 and runleft_flag = 0
standleft_flag = 0
runleft_flag = 1
play sprite 1, 1, 8, 75
px = px - 5
endif
if leftkey()=0 and runleft_flag = 1
runleft_flag = 0
standright_flag = 0
standleft_flag = 1
endif
if rightkey()=1
play sprite 1, 9, 16, 75
px = px + 5
endif
sync
LOOP
If anyone can spot what I did wrong, please notify me and I'll be very greatful. Helping me solve the problem will be very much appreciated. Thanks.