• 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!

Animated sprite begins playing at sub_image 1-WHY?

A

anthropus

Guest
here the whole proj file just in case
https://www.dropbox.com/sh/hejle9xb5t4veay/AABRwpsdZb7L6kiMUjfq4JXTa?dl=0
"Q" slows down room speed
"R" restarts room

its weird, when the sprite first plays it starts at sub image 1, skipping sub image 0 (the first one), but then when it loops it does play sub image 0. so it just skips the first sub image the first time around. i know because i slowed down the room speed so i can analyze the animation and sure enough just as i said above.

and to make matters worse, it seems as if its player that objects sprite in reverse!

it seems to be happening for all the sprites of one object only (the player object); other sprites work fine.

i searched all my code and cant seem to find why this is. is it a bug? is there something in my code that im missing?

does image_index refer to the sub_image (for example, does image_index==0 refer to sub_image 0)?

any ideas?

(all code below otherwise works good;
code below is in a script that is working fine;
the sprite in question here is the sp_celes_melee_attack...)

Code:
//melee attack state

img_spd=1;

//create correctly facing weapons obj-sprite
switch (currently_facing)
{
    case facing.upward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_up;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_up);
    }
    break;
 
    case facing.downward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_down;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_down);
    }
    break;
 
    case facing.rightward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_right;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_right);
    }
    break;
 
    case facing.leftward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_left;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_left);
    }
    break;
}

//make last frame hold


//go back to idle
if (o_par_ice_scepter_melee.image_index==6)
{
current_state=celes_state.idle;
}
 
Last edited by a moderator:
Well, looking at that code I personally cannot see anything wrong that would cause the issue you describe, so not sure WHY it's happening.

What's in the creation code of this object?
 
A

anthropus

Guest
Well, looking at that code I personally cannot see anything wrong that would cause the issue you describe, so not sure WHY it's happening.

What's in the creation code of this object?
creation code
Code:
///initialize variables, enum, and state
spd =2;
hspd=0;
vspd=0;

enum celes_state
{
idle,
andar,
melee_attack,
cast_magic,
damage
}

current_state=celes_state.idle;

enum facing
{
upward,
downward,
leftward,
rightward
}

currently_facing=facing.downward;
step event
Code:
//get player input and state switch
draw_text(x,y+16,current_state);
scr_controls();

//control celes's states

switch (current_state)
{
    case celes_state.idle:
    scr_celes_idle();
    break;
    
    case celes_state.andar:
    scr_andar();
    break;
    
    case celes_state.melee_attack:
    scr_celes_melee_attack();
    break;
    
    case celes_state.cast_magic:
    scr_celes_cast_magic();
    break;
}
idle state script
Code:
//idle state

spd=0;

//make the player do melee attack
if (melee_attack_button) {current_state=celes_state.melee_attack}

//make the player cast magic
if (spell_button)
{
current_state=celes_state.cast_magic
}

//control player's idle sprite

if (sprite_index==sp_celes_walk_up)
{
image_index=1;
image_speed=0;
currently_facing=facing.upward;
}

if (sprite_index==sp_celes_walk_down)
{
image_index=1;
image_speed=0;
currently_facing=facing.downward;
}

if (sprite_index==sp_celes_walk_left)
{
image_index=1;
image_speed=0;
currently_facing=facing.leftward;
}

if (sprite_index==sp_celes_walk_right)
{

image_index=1;
image_speed=0;
currently_facing=facing.rightward;
}

//end cast magic sprite, set idle sprite when
//coming back from cast magic state

if (sprite_index=sp_celes_cast_magic_up)
{
sprite_index=sp_celes_walk_up;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_cast_magic_down)
{
sprite_index=sp_celes_walk_down;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_cast_magic_left)
{
sprite_index=sp_celes_walk_left;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_cast_magic_right)
{
sprite_index=sp_celes_walk_right;
image_index=1;
image_speed=0;
}

//end melee attack sprite, set idle sprite when
//coming back from cast magic state
if (sprite_index==sp_celes_melee_attack_up)
{
sprite_index=sp_celes_walk_up;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_melee_attack_down)
{
sprite_index=sp_celes_walk_down;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_melee_attack_left)
{
sprite_index=sp_celes_walk_left;
image_index=1;
image_speed=0;
}

if (sprite_index==sp_celes_melee_attack_right)
{
sprite_index=sp_celes_walk_right;
image_index=1;
image_speed=0;
}

//go to andar state
if (up || down || left || right)
{
current_state=celes_state.andar;
}
"move" (andar) script
Code:
//MOVEMENT

img_spd = .3;
spd=2;

//make the player do melee attack
if (melee_attack_button) {current_state=celes_state.melee_attack}

if (up && melee_attack_button)
{
current_state=celes_state.melee_attack;
}

//make the player cast magic
if (spell_button) {current_state=celes_state.cast_magic}

//move the player
if (up)
{
vspd=-spd;
}

if (down)
{
vspd=spd;
}

if (left)
{
hspd=-spd;
}

if (right)
{
hspd=spd;
}

//set celes facing direction (modified)
//loukas skype code

if(hspd == 0)
{
   if(vspd > 0)
   {
   currently_facing=facing.downward;
   sprite_index=sp_celes_walk_down;
   image_speed=img_spd;
   }
   else
   {
   currently_facing=facing.upward;
   sprite_index=sp_celes_walk_up;
   image_speed=img_spd;
   }
}

if(vspd == 0)
{
   if(hspd > 0)
   {
   currently_facing=facing.rightward;
   sprite_index=sp_celes_walk_right;
   image_speed=img_spd;
   }
   else
   {
   currently_facing=facing.leftward
   sprite_index=sp_celes_walk_left;
   image_speed=img_spd;
   }
}


//make player not move if no input
if (!up && !down) {vspd=0;}
if (!left && !right) {hspd=0;}

//stop animation for idle
if (!up && !down && !left && !right)
{
current_state=celes_state.idle;
}

scr_collision();

melee attack script
Code:
//melee attack state

img_spd=.5;

//create correctly facing weapons obj-sprite
switch (currently_facing)
{
    case facing.upward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_up;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_up);
    }
    break;
    
    case facing.downward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_down;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_down);
    }
    break;
    
    case facing.rightward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_right;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_right);
    }
    break;
    
    case facing.leftward:
    if (!instance_exists(o_par_ice_scepter_melee))
    {
    sprite_index=sp_celes_melee_attack_left;
    image_speed=img_spd;
    instance_create(o_celes.x, o_celes.y, o_ice_scepter_melee_left);
    }
    break;
}

//make last frame hold
if (image_index==2)
{
image_index=2;
image_speed=0;
}

//go back to idle
if (o_par_ice_scepter_melee.image_index==6)
{
current_state=celes_state.idle;
}
 

TheouAegis

Member
If you don't set image_index to 0 every time you change sprite_index, you can easily skip frames. I don't see you setting image_index to 0.
 
A

anthropus

Guest
If you don't set image_index to 0 every time you change sprite_index, you can easily skip frames. I don't see you setting image_index to 0.
thanks again this did solve the problem but when i applied this solution (setting the image_index to 0) to other code, like the player's walking sprites, now the walking sprites dont animate at all!

in this code all i did was add the "image_index=0" to each section (up, down, left, right) and the walking does not animate at all, its stuck in sub_image 0, albeit in the correct direction.

is it because the idle sprites use the walking sprites and thus there is no sprite_index change? if the sprite_index does not change and you set the image_index to i, then does that make the image_speed be 0?
Code:
//set celes facing direction (modified)
//loukas skype code

if(hspd == 0)
{
   if(vspd > 0)
   {
   currently_facing=facing.downward;
   sprite_index=sp_celes_walk_down;
   image_index=0;
   image_speed=img_spd;
   }
   else
   {
   currently_facing=facing.upward;
   sprite_index=sp_celes_walk_up;
   image_index=0;
   image_speed=img_spd;
   }
}

if(vspd == 0)
{
   if(hspd > 0)
   {
   currently_facing=facing.rightward;
   sprite_index=sp_celes_walk_right;
   image_index=0;
   image_speed=img_spd;
   }
   else
   {
   currently_facing=facing.leftward
   sprite_index=sp_celes_walk_left;
   image_index=0;
   image_speed=img_spd;
   }
}
 
Last edited by a moderator:

TheouAegis

Member
When you're walking, does it really matter if you miss a frame? You could get by without setting image_index=0 when changing to the walk sprite, probably.

The issue is you set the sprite_index at very arbitrary times. If vspd is 0 and hspd is greater than or less than 0, you change the sprite. But ask yourself, "Why am I changing the sprite every step? If it was on the ground last step and moving right last step, wouldn't the sprite index be the same as last step also?"
 
A

anthropus

Guest
When you're walking, does it really matter if you miss a frame? You could get by without setting image_index=0 when changing to the walk sprite, probably.

The issue is you set the sprite_index at very arbitrary times. If vspd is 0 and hspd is greater than or less than 0, you change the sprite. But ask yourself, "Why am I changing the sprite every step? If it was on the ground last step and moving right last step, wouldn't the sprite index be the same as last step also?"
right i agree, im just trying to understand GML on a deeper level
 

TheouAegis

Member
The image_index/sprite_index issue is a GML matter.
The setting sprite_index arbitrarily every step is a logic matter, not a GML one.
 
Top