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.

AppGameKit Classic Chat / How to properly animate a sprite on player input?

Author
Message
100Megaton
13
Years of Service
User Offline
Joined: 21st Apr 2011
Location:
Posted: 26th Aug 2011 22:46
Hi everyone,

So I've been learning AppGameKit since the release, and have been blown away by it. I've been lurking here in the forums and also reading the documentation, and even visited the chat room and coupled with this great language/tool it's got me more excited to learn and eventually master something than I've been in a long time. I just wanted to thank everyone at TGC and in the community before asking my question.

Anyhow, I know this is probably bonehead simple, so I beg your indulgence. Below is the code I've put together for the player sprite in my game. The game is a vertical shooter (maybe I should call it "Yet Another Shooter"?) and I've created 7 frames of animation for it. 3 frames to bank left, 3 frames to bank right, and a center frame. I have no trouble creating the sprite and locking it to the center frame... but I can't get it to animate correctly when it gets player input to move the sprite. Instead, with the current code I've got the plane stays locked to the center frame, only randomly choosing to animate before snapping back to the center frame.

Here's the code, any tips or pointers would be greatly appreciated, thanks in advance!

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 27th Aug 2011 02:57
Your probably have your animation playing over and over and reseting it before it gets chance to animate. Try putting an if getifspriteplaying(5)=0 endif around your playsprite command.

100Megaton
13
Years of Service
User Offline
Joined: 21st Apr 2011
Location:
Posted: 27th Aug 2011 06:19
Thanks DVader, progress has been made, and the sprite is now animated!

However now I fear it's looping the animation. Without any player input the plane will first continually bank right for a while, then left for a while, then back to the right, etc.

Here's the current implementation of the move function... I suspect I am comparing the wrong variables to determine if the plane should animate or not... I appreciate any tips or advice:

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 27th Aug 2011 18:23
Well it does seem a little overcoded for player movement. Why not simply check for your input direction, -1, 0 or 1 and set the anim for that rather than this oldplane# business?
So something more in the lines

y#=getdirectiony()
x#=getdirectionx()
if x#=0
playsprite......
endif
if x#>0
playsprite..
endif
if x#<0
playsprite..
endif

The same for the y axis. You could use a case statement if you don't like so many if endifs.

I haven't tried or even looked if there is a command to set the frame rather than play through them in AppGameKit yet. But for what you are doing it may be easier. Then you can simply move up and down through the frames, dependant on what frame you are on and what direction you press.
So if you are pushing left, and it is at it's lowest frame of 1 and you press right, it will inc through all the frames until it gets to 8. If you let go at this point it will inc through until it centers. Do the same for the right and you should be set.

100Megaton
13
Years of Service
User Offline
Joined: 21st Apr 2011
Location:
Posted: 27th Aug 2011 20:02
Thanks again for your help DVader, I will try what you suggest and report back my results!
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 30th Aug 2011 00:45
Any success?

Login to post a reply

Server time is: 2024-04-23 16:00:55
Your offset time is: 2024-04-23 16:00:55