#Beginner Question About Animations

1 messages · Page 1 of 1 (latest)

tiny kelp
#

I started learning coding a few days ago by using gamemaker. Everything was going fine until i faced an animation bug.

I basically duplicated my 2 frame idle sprite and made other walking, running, jumping and falling sprites. The thing is, they're always repeating the first 2 frame. All above 2 are not running at all, can anybody please help me about it?

Here are the screenshots of my code about sprites. I also have a Draw event but forgot to take a screenshot of it.

grizzled ivy
#

do you at any point mess with image_index?

tiny kelp
#

i don't think so

#

i only have an extra draw event with a single code and that's all

#

draw_sprite_ext(sprite_index, image_index, x, y, image_xscale*face, image_yscale, image_angle, image_blend, image_alpha);

#

it's this one

grizzled ivy
#

how many frames does each sprite have?

tiny kelp
#

idle and walk 2 frames, all others 3 frames

#

i also tested one with 11 frames but still only played the first 2 frames

grizzled ivy
#

it looks like you are not doing any else clauses to those ifs so you might be getting a true condition for more than one which could be messing with you

tiny kelp
#

but how can i write it with any else clause

#

like what i wrote is basically "if this is the condition, then play this sprite" right?

grizzled ivy
#

i think gamemaker has some issues whtn you change sprite_index multiple times in one frame, so it's best to avoid doing that
let me give you an example of how you could handle it

brazen karma
#

the best course of action here in the long run is to use a state machine

grizzled ivy
#
if on_ground
 {
  if abs(xspd) >= move_spd[1]
  {
    sprite_index = runSpr;
  }
  else if abs(xspd) > =
  {
    sprite_index = walkSpr;
  }
  else
  {
    sprite_index = idle_spr;
  }
}
else
{
  if yspd > 0
  {
    sprite_index = fall_spr;
  }
  else
  {
    sprite_index = jump_spr;
  }
}
#

this should ensure that only one of these sprite_index allocations happens at once on any given frame

#

like Judacraz said, you would ideally make a state machine to handle this stuff eventually, but if you feel like that's too advanced for you, this is a start

brazen karma
#

even if it's a switch state machine

grizzled ivy
#

i don't disagree
just going off of my own journey til i started using them, I needed to learn some basics before I could wrap my head around them haha

brazen karma
#

yeah for sure

i'm just saying it as like "don't try to avoid it" kinda thing

tiny kelp
#

i think i understand the general idea, i'll give it a try now

#

tywm

#

yep it really solved the issue

#

now all animations are running properly

tiny kelp
grizzled ivy
#

like I said it's a good start, once you get mroe comfortable with coding you should definitely look into state machines

#

especially if, like Judacraz pointed out, you want to add even more states (walk, run, jump, fall, etc)

#

it'll make it more manageable than having to keep adding to an increasingly complex nested if-else web

tiny kelp
#

i'll take a look at it too, would be good to learn

#

thanks both of you again, have a great day

grizzled ivy
#

no worries and good luck