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 / Sprite animation not animating!

Author
Message
Mike Schlueter
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location: Somewhere that I\'m not suppose to be
Posted: 10th Sep 2019 01:16
Hi all!

So this is day three of me trying to debugg this issue and what started out as a simple test for the joystick has turned into quite the headache.

To explain it simply, the goal is to control a 2d character in a top down manner. Move the joystick in a direction and the sprite will animate a walking sequence, facing the corrosponding direction. The idle animation is a single frame and the walking is four in each direction (north south east and west).

Evrything seems to be working fie except for when i move the character the first frame of the walking animation is displayed and thats all until the joystick is released and the idle frame takes its place.

I’ve tried moving the placement of playsprite before, after and into the direction callups; tried moving it outside and into the loop; tried calling the play sprite once thinking it may be just playing the start frame constantly:
idle=1
if idle=0
playsprite
idle=2
endif
I’ve tried tweaking using examples on the appgamekit examples page and even rewrote the whole program.

I’m not sure what I’m doing wrong but it seems like it should work to me.

And I’ll apologize in advance...my computer commited suicide via blue screen of death so I’m solely working through the mobile appgame kit (not sure if that may be the reason, hence the photos of the code). Its not the whole program, as I left out the long list of variables and semi repeated coding. I’ve proofed it afew times so I don’t think its a typo, but like I said, I’ve been three days ons this so who knows what a fresh pair of eye’s will see.

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th Sep 2019 03:11
It will be much easier if you post the code (and graphics) rather than images
you can use code tags that look like this [*code*] (before the code) and [/*code*] (after the code) only without the *
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 10th Sep 2019 15:18
First, I can see that you use floats for start and end frames, I think integers are what is supposed to be there as you can't start frame "2 and a half" (2.5), they have to be whole.
Second, it seems like you keep calling PlaySprite which will keep starting the animation from the start frame you've defined. Just make a check if movement has started, set something like animation_playing = 1, if animation_playing = 0 then PlaySprite() so that when you move it will only call PlaySprite once, reset animation_playing whenever you need to, like when standing still.

If you intend to use joypads at some point, then you can set SetRawJoystickDeadzone, I had some troubles with deadzone making 360 degree movement "lock" to certain angles because of the deadzone, I made my own deadzone code instead.
13/0
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 11th Sep 2019 00:00 Edited at: 11th Sep 2019 01:16
Quote: "First, I can see that you use floats for start and end frames, I think integers are what is supposed to be there as you can't start frame "2 and a half" (2.5), they have to be whole."

Yep, integer for frames. Good call Cybermind.

Not trying to wrap my head around your code, but I ran into this starting out playing animations and here was what was going on in my code...

It will play the animation each cycle of the main loop when the conditions are met, so it will keep starting it over and over which keeps it at frame 1.

My solution was to check the usual conditions for input, then before playing the animation I also check to see if it is playing already.

That prevents it from starting again if it is already playing, and then it only starts over if it has reached the end like it is supposed to, rather than starting frame 1 every cycle of the main loop.

There are several ways to do that.

One way is like mentioned above having a variable for a flag, then there are also some commands that will check animation states.

Here is a snippet of a pair of layers animating with only two frames, so I just check the frame it is on...



Usually you will have more frames than just two for sprites, but I think you will get the idea.
These sprites have more animations that were loaded from the same sprite sheet, so those are the two frames I need to make sure it was not on already to know that this animation was not already playing.
Probably could have just checked one sprite, since the layers work together, but I checked both just to be thorough, and to be easier for me when looking back at it later.
Which would have looked like this...



These layers were for legs and body movement for a cartoon style animation, so the legs were twice the speed as the body.
The head was a separate layer with a single frame for the direction. ( SetSpriteFrame(character_selected,2) )
This was a snippet to allow me to preview different characters as I was creating them, hence the character_selected variable.
Only the heads were different, with the legs and body sprites being shared, and made in a base white with code to change the colors depending on the character selected.

You could easily change this to check for a range of frames for any length animation instead of just the two by using the > and < instead of <>.

Anyway, making sure that the animation is not already playing before playing it will ensure that the continual 1st frame issue won't happen.

I hope this helps.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Mike Schlueter
18
Years of Service
User Offline
Joined: 28th Nov 2005
Location: Somewhere that I\'m not suppose to be
Posted: 11th Sep 2019 21:27
Cheers Cybermind and Conjured, adding the flag check for playsprite worked like a charm. I had to move the actual playsprite code to the end after checks (which makes sense) so the animations would sync correctly but that was the trick.

I had tried that before but obviously i did it wrong lol.
Would you guys know of a tutorial for tips on code order placement and logic?

Login to post a reply

Server time is: 2024-04-20 00:48:46
Your offset time is: 2024-04-20 00:48:46