So sorry but I have a question (Animation)

D

Drew

Guest
So i've been mulling over this for a couple days and I am no closer that I was to solving this...in fact..in some cases I made it worse..

Anyways, sorry if this is not the place to properly post this, although i'm pretty sure it is. Oh well, i've perused through the forums and have not found an answer to my problem so I will post it here in hope thats this awesome Jawsome community will help me out.

So here's the deal. I'm trying to set up animations (I know, newbie right?) well not completely. I have all the other character animations working i.e jump crouch idle, and hey i even got a working attack animation with collisions and everything! but for some reason my run animation refuses to work using the logic I have given it. i have variables set for hsp (var for actor to determine the speed of movement) anyways in order to get the animation working i set the code like so
Code:
if (hsp!=0)
{
     sprite_index = sprite_actor run
}
and before i go on further i have the code:
Code:
if (move!=0) image_xscale = move;
i have a move var that is binded to the keys left and right that are searching for a value between 1 and -1 and combined with the previous code should( and does) control the character facing..
so yeah, why won't this guy run! Plus if you need more code i will be happy to supply it, i don't want to post it all (and probably end up confusing some) but i will post more if asked! i would really appreciate the help, i'll go bald if this goes on any longer
 
M

McWolke

Guest
"sprite_index = sprite_actor run" <- there is a "_" missing between "actor" and "run".
might this be the problem?
 
D

Drew

Guest
Nope that was a typo on my part...here's the segment of code copy pasted so that doesn't happen again...so sorry about that!!!
Code:
//animate
//facing the direction of movement
if (move!=0) image_xscale = move;

if (hsp!=0)
{
    if (grounded)
    {
        sprite_index = sprite_actor_run
    }
    else
    {
    sprite_index = sprite_actor
    }
}
else
{
    if (vsp<0)
    {
        sprite_index=sprite_actor_jump;
    }
    else
    {
        sprite_index=sprite_actor;
    }
}


//attacking
//hitbox
if attacking

{
    sprite_index=sprite_actor_whip {image_speed = 0.1;}
    movespeed = 0;
    jumpsmax = 0;
    if(image_index >= 2)
    {
        with(instance_create(x,y,object_whip_hit))
        {
            image_xscale= other.image_xscale;
            with(instance_place(x,y,eobject))
            {
                if(hit ==0)
                {
                    hit = 1;
                    vsp = -3;
                    hsp = sign(x - other.x) * 4;
                    image_xscale = sign(hsp);
                }
            }
        }
    }
}
 
D

Drew

Guest
So upon further time to myself and constant thinking, i'm wondering if the sprite_actor_run animation is stuck on image_index 0....although...i don't know why or how to check it if it was?
 
M

McWolke

Guest
Do you set the image speed anywhere else? Because in this code you just set the sprite, but not the image_speed.
 
B

Belactriple9

Guest
so this is what I got, I hope it helps, it works fine for me.
Code:
if keyboard_check(vk_left) or keyboard_check(vk_right) or keyboard_check(ord('A')) or keyboard_check(ord('D')){move=1}else{move=0}
//
if (move!=0)
{
sprite_index = spriteWalk;
image_speed = .5;}else{image_index=spriteIdle}
actually this is what I use for movement always w/ jumping and walking/running
Code:
///movement and misc
//place this in a collision event w/ whatever you want to stop on:
//if place_meeting(x,y+1,[object]){vspeed=0;move_contact_solid(270,12)}
//Animation

if keyboard_check(vk_left) or keyboard_check(vk_right) or keyboard_check(ord('A')) or keyboard_check(ord('D')){move=1}else{move=0}
//
if (move!=0)
{
sprite_index = spriteWalk;
image_speed = .5;
}
if keyboard_check(vk_nokey){sprite_index=spriteIdle}
//
if (place_meeting(x,y+1,objectWall)){}
else
{if (vspeed < 0) {sprite_index = spriteJump
image_speed=.15}else{ sprite_index = spriteFall}}
//movement right and left
if keyboard_check(vk_right){image_xscale=1;hspeed=5}
if keyboard_check(vk_left) {image_xscale=-1;hspeed=-5}
if !keyboard_check(vk_right) and !keyboard_check(vk_left){hspeed=0}
//A&&D
if keyboard_check(ord('D')){image_xscale=1;hspeed=5}
if keyboard_check(ord('A')){image_xscale=-1;hspeed=-5}
if !keyboard_check(ord('A')) and !keyboard_check(ord('D')){hpseed=0}
//jumping
if (!place_free(x,y+1)){
gravity = 0;gravity_direction = 270;vspeed = 0;}
//
else{gravity = 1.5 //whatever # U want
gravity_direction = 270;}
//
if (vspeed > 15){vspeed=15}
//
if (keyboard_check(vk_up)) or keyboard_check(ord('W')){
if (!place_free(x,y+1))
{ vspeed = -12; /*change this number to fit jump height wanted*/ }}
 

Yal

🐧 *penguin noises*
GMC Elder
If you set it unconditionally to a sprite with fewer subimages earlier in the code, it'll clamp the subimage to fit. So if you set it to the idle sprite first always and THEN check if you should use the run sprite, you'll limit the run sprite to the number of subimages in the idle sprite.
 
D

Drew

Guest
so this is what I got, I hope it helps, it works fine for me.
Code:
if keyboard_check(vk_left) or keyboard_check(vk_right) or keyboard_check(ord('A')) or keyboard_check(ord('D')){move=1}else{move=0}
//
if (move!=0)
{
sprite_index = spriteWalk;
image_speed = .5;}else{image_index=spriteIdle}
actually this is what I use for movement always w/ jumping and walking/running
Code:
///movement and misc
//place this in a collision event w/ whatever you want to stop on:
//if place_meeting(x,y+1,[object]){vspeed=0;move_contact_solid(270,12)}
//Animation

if keyboard_check(vk_left) or keyboard_check(vk_right) or keyboard_check(ord('A')) or keyboard_check(ord('D')){move=1}else{move=0}
//
if (move!=0)
{
sprite_index = spriteWalk;
image_speed = .5;
}
if keyboard_check(vk_nokey){sprite_index=spriteIdle}
//
if (place_meeting(x,y+1,objectWall)){}
else
{if (vspeed < 0) {sprite_index = spriteJump
image_speed=.15}else{ sprite_index = spriteFall}}
//movement right and left
if keyboard_check(vk_right){image_xscale=1;hspeed=5}
if keyboard_check(vk_left) {image_xscale=-1;hspeed=-5}
if !keyboard_check(vk_right) and !keyboard_check(vk_left){hspeed=0}
//A&&D
if keyboard_check(ord('D')){image_xscale=1;hspeed=5}
if keyboard_check(ord('A')){image_xscale=-1;hspeed=-5}
if !keyboard_check(ord('A')) and !keyboard_check(ord('D')){hpseed=0}
//jumping
if (!place_free(x,y+1)){
gravity = 0;gravity_direction = 270;vspeed = 0;}
//
else{gravity = 1.5 //whatever # U want
gravity_direction = 270;}
//
if (vspeed > 15){vspeed=15}
//
if (keyboard_check(vk_up)) or keyboard_check(ord('W')){
if (!place_free(x,y+1))
{ vspeed = -12; /*change this number to fit jump height wanted*/ }}

So I perused through this and even tried implementing a bit of your code to my configuration...it's making me think that the sprite is clamped to the first image_index....
EDIT forgot to mention that it didn't work...i don't understand why my attack animation will play but the run is locked to an individual frame
 
D

Drew

Guest
First off thanks for all the freakin sweet comments! Yal! you seem to be correct...i deleted the first frame of the run animation since it was the same as my idle frame and turns out..it is locked. I perused through my step event code for my actor and i found only one instance of image_index but it was only to apply to attack animations and when i deleted that piece of code there was no change...How in the world could I find it?

this is the whole code in the actor step event...
all the other code doesn't contain an index reference so i'm not sure how to go about fixing this
Code:
actorstandardmovement();

if keyboard_check(ord("A"))
{
    attacking = true;
}

grounded = place_meeting(x, y + 1, object1)



//Debug Restart
key_restart = keyboard_check(vk_tab);

  
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;


if (grounded)
    {
        jumps = jumpsmax;
    }

if (key_jump) && (jumps > 0)
{
    jumps -= 1;
    vsp = -jumpspeed;
}

//glide

if grounded = false && keyboard_check_pressed(ord("S"))
{    
    glide = true;
}

else
{
    if grounded = true
    {
        glide = false;
    }
}
if glide = true
{
    grav = 0.1;
}
else
{
    grav = 0.4;
}

//Slide

  


//Variable Jump Height
if (vsp <0) && (!key_jump_held) vsp = max(vsp,-jumpspeed/4)

//moving platforms
var hsp_final = hsp + hsp_carry;
hsp_carry = 0;



//Horizontal Collision
if (place_meeting(x+hsp_final,y,object1))
{
    yplus = 0; //variable for checking for slopes
while (place_meeting(x+hsp_final,y-yplus,object1) && yplus <= abs(1*hsp_final)) yplus += 1;
    if place_meeting(x+hsp_final,y-yplus,object1) //previous line of code has been determined true
    {
        while (!place_meeting(x+sign(hsp_final),y,object1)) x+=sign(hsp_final);
        hsp = 0;
        hsp_final = 0;
    }
    else
    {
    {
        y -= yplus;
    }
        x += sign(hsp_final);
    }
    hsp_final = 0;
    hsp = 0;
}
x += hsp_final;

//Vertical Collision
if (place_meeting(x,y+vsp,object1))
{
    while(!place_meeting(x,y+sign(vsp),object1))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;

//Restart
if (key_restart)
{
    game_restart();
}

if (object_actor.hp <= 0)
{
    game_restart();
}

//animate
//facing the direction of movement
if (move!=0) image_xscale = move;

if (hsp!=0)
{
    if (grounded)
    {
        if sprite_index!=sprite_actor_run image_index = 0;
        sprite_index = sprite_actor_run; {image_speed = 0.1;}
    }
}
else
{
    if (vsp<0)
    {
        sprite_index=sprite_actor_jump;
    }
    else
    {
        sprite_index=sprite_actor;
    }
}


//attacking
//hitbox
if attacking

{
    sprite_index=sprite_actor_whip {image_speed = 0.1;}
    movespeed = 0;
    jumpsmax = 0;
    if(image_index >= 2)
    {
        with(instance_create(x,y,object_whip_hit))
        {
            image_xscale= other.image_xscale;
            with(instance_place(x,y,eobject))
            {
                if(hit ==0)
                {
                    hit = 1;
                    vsp = -3;
                    hsp = sign(x - other.x) * 4;
                    image_xscale = sign(hsp);
                }
            }
        }
    }
}


if !attacking
{
movespeed = 2;
jumpsmax = 2;
}

//Powerups


//debug 1

if (sprite_index!=sprite_actor_whip) image_index = 0;

I guess my other question would be with what I have now for animating movement, should it work?
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
At the very last line...
Code:
if (sprite_index!=sprite_actor_whip) image_index = 0;
Note that "not whip sprite" includes the run sprite. You also have 'debug' on the line above, so if that's just debug code, you might want to remove it completely.
 
D

Drew

Guest
@Yal yeah i tried that...it didn't help...unfortunately...

i'm really at a complete loss...the logic is sound...i double checked for any instances that bind the image_index to the first frame...

This is like a carnivorous earwig thats eating its way through my ear to my brain...i just don't understand
 

Yal

🐧 *penguin noises*
GMC Elder
If you absolutely can't find the solution, you could always cheat by creating your own variables. Try forcibly setting the subimage to something other than the first frame, first of all... if that works, we could work around it, otherwise we can't.

Either way, you might want to use Search In Scripts to find ALL code that modifies image_index and/or image_speed (search for either of them) in case you missed any when you manually looked for it. It's a very powerful tool for finding code in cases like this.
upload_2016-7-7_3-19-13.png
 
D

Drew

Guest
okay so I tried reassigning to the keys themselves...i've searched using the search in scripts tool....I have found no results yet...it's so peculiar that the attack animation runs flawlessly but the run does not
 
D

Drew

Guest
ahh yes it does...i tried deleting it once before and it didn't seem to have any effect! that's so wierd...of course that gives me a new problem...because i put that code in there so the attack animation would start from the beginning because it seems to start from any frame otherwise

so is it possible to force an animation frame to start from 0 without affecting all the animations

or do I have to start a new thread?:p
 
Last edited by a moderator:
Top