• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Buggy crawling animation (GMS2, Windows)

C

Cam Croft

Guest
Gamemaker Studio 2, Windows

Like the title says-
I'm using draw_sprite_ext in the draw event to do my animations, and finding the control very favorable...
However! I can't get my player to draw slightly higher during part of its 2 frame run animation

///Draw Event Animation

//change player facing appropriately
if (hsp != 0) image_xscale = sign(hsp);

//airborne animation
if (!wall_below)
{
draw_sprite_ext(s_playera, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}

//standing still
if (wall_below && hsp == 0) //if touching floor, not moving
{
draw_sprite_ext(s_player, 1, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}

//running
if (wall_below && hsp != 0)
{
draw_sprite_ext(s_player, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
if(image_index == 0)
{
draw_sprite_ext(s_player, image_index, x, y-1, image_xscale, image_yscale, 0, c_white, 1 );
}
}

My problem here is in the //running section! I'm getting the animation I want, but image_index 0 of s_player is drawn at the same y position of image_index 0.

Does image_index not work in this regard? Anybody know what I'm doing wrong? Or of any cleaner alternatives? I want the checked effect, below, but I have the x, currently!:

upload_2018-1-16_15-0-55.png
 
C

Cam Croft

Guest
update: figured it out on my own!

//running
if (wall_below && hsp != 0)
{
if (round(image_index) == 0)
{
draw_sprite_ext(s_player, image_index, x, y-1, image_xscale, image_yscale, 0, c_white, 1 );
}
else
{
draw_sprite_ext(s_player, (image_index), x, y, image_xscale, image_yscale, 0, c_white, 1 );
}
}

this is the code I used, which I'll leave up for the benefit of other newbies. Not the most legible, but it seems to get the job done! The change from image_index == 0 ---> round(image_index) == 0
...was evidently important! I guess image_index isn't an integer value...which...makes sense.
 
C

Cam Croft

Guest
followup: Now I'm struggling with the crawling animation!
Ducking works fine, but when my crawling animation plays, it only plays the first 2, frames(i believe) of 4
upload_2018-1-17_12-14-13.png
this is what I have for the animation editor
this is my code VVV

//ducking
if (wall_below && key_down && hsp == 0)
{
draw_sprite_ext(s_playerc, 0, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}

//crawling
if (wall_below && key_down && hsp != 0)
{
draw_sprite_ext(s_playerc, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}
 
B

Badger

Guest
I normally use

Code:
floor(image_index)
but you get the idea.
As for the crawling thing, what is your image_speed set to?
Also, a slightly more efficient way of writing what you have:

Code:
if(wall_below){
 if(key_down){
  if(hsp!=0){
   draw_sprite_ext(s_playerc, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }else{
   draw_sprite_ext(s_playerc, 0, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }
 }
}
 
C

Cam Croft

Guest
I normally use

Code:
floor(image_index)
but you get the idea.
As for the crawling thing, what is your image_speed set to?
Also, a slightly more efficient way of writing what you have:

Code:
if(wall_below){
 if(key_down){
  if(hsp!=0){
   draw_sprite_ext(s_playerc, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }else{
   draw_sprite_ext(s_playerc, 0, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }
 }
}
Currently, my image_speed is set to 0.1 frames per game frame in the sprite editor (that's what determines image_speed, right?)
And is no longer animating(change of animation speed in the sprite editor is all I've changed, at this point), although its horizontal position 'jitters' one pixel ahead when I crawl. I think it was happening before, but was less obvious with more animation happening.

The jittering, I suspect, is due to this being a very low res game, and not having my player's x and y coordinates rounded(my crawl speed variable is not an integer), but the animation weirdness is...troublesome.

Is flooring image_index considered good practice?
Thanks for the advice on nested if statements! I've heard it's the way to optimize, and was gonna take a crack at it once I got this code working.
 
C

Cam Croft

Guest
Here's my complete draw event code, in case I messed something up in prior code

Code:
// ANIMATION

//determine facing thru image xscale
if (hsp != 0) image_xscale = sign(hsp);

//airborne animation
if (!wall_below)
{
    draw_sprite_ext(s_playera, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}

//standing still
if (wall_below && hsp == 0 && !key_down) //if touching floor, not moving
{
    draw_sprite_ext(s_player, 1, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}
    
//walking
if (wall_below && hsp != 0 && !key_down)
{
    if (floor(image_index) == 0)
    {
        draw_sprite_ext(s_player, image_index, x, y-1, image_xscale, image_yscale, 0, c_white, 1 );
    }
    else
    {
        draw_sprite_ext(s_player, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
    }   
}   

//ducking
if (wall_below && key_down && hsp == 0)
{
        draw_sprite_ext(s_playerc, 0, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}

//crawling
if (wall_below && key_down && hsp != 0)
{
    draw_sprite_ext(s_playerc, floor(image_speed), x, y, image_xscale, image_yscale, 0, c_white, 1 );
}
 
B

Badger

Guest
So the problem seems to be with this:
Code:
//crawling
if (wall_below && key_down && hsp != 0)
{
   draw_sprite_ext(s_playerc,   >>>>floor(image_speed)<<<<  , x, y, image_xscale, image_yscale, 0, c_white, 1 );
}
You said that image_speed was set to .1
floor(image_speed) will always equal 0, so your image index will not really change...
You might try something like:
Code:
 floor(image_index)
 
B

Badger

Guest
One more thing,
Code:
// ANIMATION

//determine facing thru image xscale
if (hsp != 0) image_xscale = sign(hsp);

//airborne animation
if (!wall_below){ //nothing below
   draw_sprite_ext(s_playera, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
}else{ //something below
 if(!key_down){
  if(hsp==0){ //standing still
   draw_sprite_ext(s_player, 1, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }else{
   if (floor(image_index) == 0){
     draw_sprite_ext(s_player, image_index, x, y-1, image_xscale, image_yscale, 0, c_white, 1 );
   }else{
     draw_sprite_ext(s_player, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1 );
   }
  }
 }else{ //if key_down
  if (hsp == 0){
   draw_sprite_ext(s_playerc, 0, x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }else{
   draw_sprite_ext(s_playerc, floor(image_index), x, y, image_xscale, image_yscale, 0, c_white, 1 );
  }
 }
}
 
Top