Why I could not make player walking animation?

Hello, I tried to make my player sprite walking animation by display 2 different pictures but it always fails, anyone gives me some tips or it is a bug? It‘s by check the remainder of x/2, here is the code:

11

thanks!

The issue here is that sprite.x isn’t an integer but just a normal number; 3.5 is a valid x position, and remainder of 3.5 % 2 is 1.5. (This is mainly necessary to maintain accurate movement across different frame rates / even with low speeds). You’re almost never going to hit the == 0 case if you aren’t explicitly setting x (e.g. using the move sprite block or velocity will leave remainders at times).

Probably easiest fix is to use a truncate block around kid x (note also that remainder can br negative, but that should be fine with the truncate in the right spot). That block is in the same dropdown as round, and just cuts off the fractional portion of a number.

It might also be worth looking at the animations extension for setting up simple animations (with help in the image editor to preview / show previous frames). Richard also wrote the https://github.com/riknoll/character-animations extension, though thats a bit newer / more complex - its super useful for having full animation sets for different directions / etc.

3 Likes

Thank you so much for your reply! I tried truncate block it works quite well!
However, the https://github.com/riknoll/character-animations extension seems had been removed?

BTW, I use the remainder trick by learning from this official video:


notice: at 23:02 begins to make the cat walking animation without truncate block.
Should we consider it as a bug or version difference maybe?

thanks again!

Ahhh, that was a bug in an older version of arcade almost a year ago that caused the values to be stored as floats but read out as ints - this behavior broke a number of things, e.g. having change mysprite x by .1 would actually move the sprite slightly to the left half the time. @darzu maybe we can add a comment on the video noting this behavioral difference?

Thanks for pointing that out!

Also, it looks like the extension is still there to me? Is it not showing up when you paste the github url into the extensions dialog?

1 Like

Great, understood!
the extension appears by paste the Github url on the extensions dialog but I didn’t find a character animation option on the toolbar. Does it just add some like walking animation blocks in Animation tools?
222


I am new and not quite familiar with the blocks
thanks

It should be the category right above ‘advanced’ in that acreenshot, ‘Character’:

SmartSelect_20201213-095707_Chrome

1 Like

Yes thanks for pointing this out. I’ll post a comment on the video. It was always a little bit odd, so I’ll try to find a better way to do this.