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.

Newcomers AppGameKit Corner / About changing animations after keypresses

Author
Message
Cuurian
7
Years of Service
User Offline
Joined: 17th May 2016
Location: Hermosillo, Mexico
Posted: 17th May 2016 05:22
Hi Guys, Im having a little problem trying to make the following:
Im trying to make a platforming game, where im using spritesheets as animations, i want the character to move left and right, then change animations depending of which position is the character facing

The code is a mess and i did not put any input code yet, but i need a way to switch animations when, for instance the left or right key are pressed, then stop the animation when the buttons are unpressed

theres the sample, messy code, where depending of the variable "Cuurian" (character's name) is the animation it shows.


thanks in advance
Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 17th May 2016 14:35 Edited at: 17th May 2016 14:37
Add a conditional that reads the input (going left or right) and depending on that just flip the sprite using SetSpriteFlip(i, h, v). i is sprite index, h is horizontal orientation (0 normal, 1 flipped) and v is vertical orientation (0 normal, 1 flipped). If no input, then stop the sprite animation using StopSprite(i).
Cuurian
7
Years of Service
User Offline
Joined: 17th May 2016
Location: Hermosillo, Mexico
Posted: 18th May 2016 00:10 Edited at: 18th May 2016 04:28
Thanks for the quick response, its pretty good to hear theres a sprite flip function.

I have a separate sprite sheet for the standing animation, how do i make the same sprite switch to a diferent file?

EDIT: i need a way to update when the states change so i can change animations, i need to update every time the state variable changes
Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 19th May 2016 00:49 Edited at: 19th May 2016 00:52
set up a simple conditional that orients your sprite (and starts and stops its' animation) depending on input. something like this:



As for the input-control code, AppGameKit got a good help-system that will get you going on how to set that up.

Happy coding
Cuurian
7
Years of Service
User Offline
Joined: 17th May 2016
Location: Hermosillo, Mexico
Posted: 19th May 2016 02:39
Thank you so much, i did a similar code but less organized than yours lol
But if i want to play an animation for the character standing instead of just stop the animation?, im having a hard time trying to switch sprites
Also, i dont know a effective way to update the animations when the joystick state changes, in my current code if i move the joystick the animation repeats every milisecond so looks very weird
Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 19th May 2016 13:46
ah, hehe, my bad. Should have used ResumeSprite(i) rather than PlaySprite(i) in my example. Then the sprite will continue where it left off, rather than start over again. Also, when you stop and you want the sprite to rest on a specific frame, use SetSpriteFrame(i, frameIndex) after calling the StopSprite(i) command.

If you want to have the sprite doing something when standing still, you need add a few frames to your sprite. Say frame 0 to 24 are the walking animation, and frame 25 to 49 are the standing still animation. When walking you call PlaySprite like so:

PlaySprite(i, 30, 1, 0, 24)

and when standing still:

PlaySprite(i, 30, 1, 25, 49)

Where the parameters are sprite Index, frames per seconds of playback, looping on or off, start frame and lastly end frame.

For it to work properly, you'll need to set a flag so that you do not start over and over from frame zero when walking. Something like this:



There are comprehensive descriptions of all the sprite commands in the help file. Just navigate to Home->Commands->Sprite

Login to post a reply

Server time is: 2024-04-16 21:40:53
Your offset time is: 2024-04-16 21:40:53