Animation not working in this code

Hi,

This game is a work in progress; I am trying to figure out why the animation is not working… the players legs are supposed to move when walking. Any help would be greatly appreciated.

1 Like

Nice game idea and graphics, @jaturn68!

I am no expert in this field, but trying to get better coding in MakeCode Arcade, especially since pupils keep asking about similar challenges with their own creations, which I have a hard time figuring out within the average span of a modern kid’s attention… :wink:

Handling movements in multiple directions, with jumps and weapons, and with animations, is a task that generally requires careful attention to details and keeping track of a quickly growing number of states, among other things and quirks of the MakeCode Arcade game engine, I am starting to learn.

In this particular game, I have found three common issues which also are recurring among pupils:

  1. The most common issue with animations not working, is typically not letting the animation play out uninterrupted, which has to do with handling states and keeping them going in parallel without being interrupted. @richard has made a nice character animation extension, which has a number of common predicates predefined, (is)moving right, (is)facing left etc., to help one keep track of such states, which I can recommend using.
    Specifically, in the game link you presented here, the walking animation is interrupted on every game loop by setting a new sprite image and because the animation is started anew before it got the time to progress to the next image.
    Skjermbilde

  2. The next challenge that I struggled a bit with here, after attempting to keep track of states manually and using the character animation extension, was that the various sprite images used did not have the same dimensions, thus also triggering a movement(and predicate/state change) every time a sprite image was changed, since the sprite (x,y) position is determined by the sprite’s upper left corner pixel. This can be solved, for instance like I chose to do here, by making all link character sprites the same dimension, 15x17, or - like I did in my example for the sprite image while lying down flat in the air- by not using any condition/predicate that has to do with horizontal left or right movement in the main game loop’s if-statements.

  3. Another small challenge was that I did not get the facing right or facing left predicates to work correctly even with same-sized sprite images which did not trigger movement when changing images. I then had to make my own state variable, faceLeft, which changes with the left and right buttons, respectively.

  4. The last challenge was that any sprite image that was not 16x16 dimension, exhibited uneven motion horizontally for every vx speed which were not a factor of 50, for some strange reason that I have addressed in its own topic(link will be provided later). That I solved by setting vx to 100, but could also be fixed by setting all sprites to 16x16.

Here is my attempt at fixing various challenges with animation etc. in the code provided by @jaturn68 above:

In addition to the “fixes” above, I also added double-jumb logic to be able accomplish the long and high jumps in the tilemap, rewrote the sword handling with 2 sprites instead of just on, inspired by this nice example and implemented movement and animation in both left and right directions, to highlight the logic needed for all this in the code.

Because I am a noobie at this myself, I find it is harder to modify other’s code than designing my own from scratch and I did not have unlimited time available for this, my resulting code is by no means especially good, neither in handling nor readability.

But, judging by how hard it was(at least for me) also to search for really good examples of well written code with fluent movement and animations in many direction and with many actions(jumps, weapons etc.) on this forum and in the documentation(just small examples), and by how frequently similar questions arise, it would be great if @richard / the @MakeCode could provide the forum with one such elaborate best practice example for everyone to learn from, like @richard recently did perfectly for hitboxes.

Here are some examples I did manage to find, with really great movements and animations, some complexity and fairly readable/organized code:

  1. https://makecode.com/_1mAeq2Rzb7rd (This is just a repost of this nice game @NotOnefinity with only the blocks pertaining to movement and animation expanded. The game uses the character animation extension and the code is really well organized.)

  2. https://forum.makecode.com/t/castle-crawler/1343 (this is the official forum link to @reyhanPanci256’s nice Castle crawlder, which is also featured on the arcade.makecode.com frontpage in the Community games section. Here all the states and animations are manually programmed without the character animations extensions. Adding, for instance, horizontal movements and club strikes, would complicate the code with manyfold additional state combinations

Here’s the updated link to the topic about sprite size vs smooth movements:

Perhaps this very thread could work as the best practice example, where @richard / the @makecode team / someone on this forum enhances/optimizes @jaturn68’s code to work fluently with animations in all directions and for all actions, and rewrite the code to be:

  • both efficient and more readable,
  • with silky smooth movements and animations, and
  • immune to hang-ups and strange behavior resulting from hammering many buttons at the same time?

The pfps :rofl: :rofl: :rofl:

Tri-ambiguous!

1 Like