1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 Disappearing chicken? Sprites disappearing during animation.

Discussion in 'Programming' started by justloveme94, Dec 1, 2019.

  1. justloveme94

    justloveme94 Member

    Dec 5, 2017
    Hello everyone, I apologize for my newness but I have been banging my head against a wall trying to solve this problem. I have been following Friendly Cosmonaut's tutorial series. i decided to change up the code that was provided for the NPCs for the rest of my other sprites to walk around randomly. I thought I made the necessary changes, but my sprites will walk around randomly and then disappear and then reappear at a different location. I presume the problem lies with the draw event but I'm not sure.

    CREATE Event
    w_spd = 1;
    n_spd = 2;
    r_spd = 3;
    spd = w_spd;
    x_frame = 0;
    y_frame = 1;
    x_offset = sprite_get_xoffset(mask_index);
    y_offset = sprite_get_yoffset(mask_index);
    spr_chicken = spr_chicken_walk;
    //c_shadow = spr_chicken_shadow;
    moveX = 0;
    moveY = 0;
    can_move = true;
    alarm[1] = 1;

    DRAW Event
    var c_anim_length = 4;
    var c_frame_size = 32;
    var c_anim_speed = 6;
    var xx = x-x_offset;
    var yy = y-y_offset;

    if(x_frame + (c_anim_speed/60) < c_anim_length -1) { x_frame += c_anim_speed/60; }
    else { x_frame = 1; }
    if (moveX < 0) y_frame = 1; //left
    else if (moveX > 0) y_frame = 3; //right
    else if (moveY < 0) y_frame = 4; //up
    else if (moveY > 0) y_frame = 2; //down
    else x_frame = 0;

    if(spr_chicken != -1) draw_sprite_part(spr_chicken, 0, floor(x_frame)*c_frame_size, y_frame*c_frame_size, c_frame_size, c_frame_size, xx,yy);

    moveX = 0;
    moveY = 0;
    var idle = choose(0,1);
    if(idle == false) {
    var dir = choose(1,2,3,4);
    switch(dir) {
    case 1: moveX = -spd; break;
    case 2: moveX = spd; break;
    case 3: moveY = -spd; break;
    case 4: moveY = spd; break;
    alarm[1] = random_range(2.5, 4)*room_speed;
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Apr 13, 2016
    Without analysing the code too much, I notice these lines:

    if (moveX < 0) y_frame = 1; //left
    else if (moveX > 0) y_frame = 3; //right

    Shouldn't that be x_frame and not y_frame?
  3. justloveme94

    justloveme94 Member

    Dec 5, 2017
    Unfortunately that only caused the chicken to perform the cha, cha slide. He also continued to disappear sadly. The code is almost the same for the NPCs. I switched out the sprite of the chicken for one of the human NPCs and the code performed correctly. I wonder if it is something with my sprite sheet and the code?

    Attached Files:

  4. TailBit

    TailBit Member

    Oct 16, 2019
    else if (moveY < 0) y_frame = 4; //up
    shouldn't it be y_frame = 0;

    because the up sprite is on the first row .. and 4 would be the 5th row
  5. Catastrophe

    Catastrophe Member

    Sep 22, 2019
    It seems like what you're doing is taking a large sprite sheet and using it as a single single sprite, using draw_sprite_part to draw the appropriate sprite's frame.

    Isn't it just easier to just make 4 sprites? Like you can do it this way, but I don't know anyone else that does really. That's one of the advantages to GMS's animation system, you can just do "sprite_index = <whatever>" and you're done, no 50 lines of code monstrosity. When you want the chicken to stop, just use image_speed = 0 and change it back when you're done.

    https://www.piskelapp.com/ is great for chopping up spritesheets into different gifs if that's what you need. (edit: actually, in GMS it is pretty easy to do as well, just go to import sprite sheet and select only the row you need)

    But if you really want to do it this way, we'd need to see the sheet for the human as well, since if it's working for that, but not this, it'll probably be pretty easy for us to figure out.

    Edit TailBit is probably correct, though. But I don't get why it would fail for the chicken but not the NPC o_O
    Last edited: Dec 2, 2019
  6. TheouAegis

    TheouAegis Member

    Jul 3, 2016
    Hmmm... o_O

    That should probably be "else { x_frame = 0; }"

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice