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

GameMaker Animations not working as expected[SOLVED]

M

maranpis

Guest
Hello Guys,

First I want to say i'm just 2 months with gamemaker studio 2, so this is a noob question, hope you can help me:

I'm doing the moving_script for the player:

Code:
// Moving and collision

if keyboard_check(vk_right)
{
        hospeed=20;
        sprite_index=s_Running
        image_xscale=1;
        }
        else if keyboard_check(vk_left)
        {
        hospeed=-20    ;
        sprite_index=s_Running
        image_xscale=-1;
        }
        else
        {
        
        hospeed=0;
        sprite_index=s_Idle;
        }
        
// COLLISION X
        
if place_meeting(x+hospeed,y,o_Ground)
{
        while !place_meeting (x+sign(hospeed),y,o_Ground)
        {
        x+=sign(hospeed);
        }
        hospeed=0;       
}

x+=hospeed;
//GRAVITY AND JUMPING

if !place_meeting (x,y+1,o_Ground)
{
        
        vespeed+=grav
        
        }
        else
        {
        if keyboard_check_pressed(vk_up)
        {
        
        vespeed=-20;
        
        }
}

// COLLISION Y

if place_meeting(x,y+vespeed,o_Ground)
        {
        while !place_meeting(x,y+sign(vespeed),o_Ground)
        {
        y+=sign(vespeed);
        }
        vespeed=0;
}

y+=vespeed;

When I import a standar rectangle sprite all the movements works fine.

But when I change this for the animations, the player get stucks on the ground.

¿Why this is happening?

Thanks for your help.

----MORE INFO----

-I'm using Spine 2d but I exported all the animations frame by frame.

-The spirte size is 340x358.


-If the player is not touching the ground, left and right animations runs and moves fine.
 

Attachments

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, the issue here is that collisions are based on the COLLISION MASK, which in turn is based on the sprite currently assigned to the instance. So, if you change the sprite or you change the scale or rotation, you also change the collision mask and so it can get "stuck" in other instances around it. The solution to your problem is to create a special rectangular mask sprite (the same size as the collision mask of the sprite that works for you), and then assign that as the instance's MASK INDEX. The mask_index is a special sprite that won't be drawn but will be used instead ONLY for collisions. In this way you can draw whatever you want as the instance sprite, and collisions will always be based off of the mask rather than the sprite.

See the section on the collision mask here: http://docs2.yoyogames.com/index.html?page=source/_build/2_interface/1_editors/objects.html
 
M

maranpis

Guest
Okay, the issue here is that collisions are based on the COLLISION MASK, which in turn is based on the sprite currently assigned to the instance. So, if you change the sprite or you change the scale or rotation, you also change the collision mask and so it can get "stuck" in other instances around it. The solution to your problem is to create a special rectangular mask sprite (the same size as the collision mask of the sprite that works for you), and then assign that as the instance's MASK INDEX. The mask_index is a special sprite that won't be drawn but will be used instead ONLY for collisions. In this way you can draw whatever you want as the instance sprite, and collisions will always be based off of the mask rather than the sprite.

See the section on the collision mask here: http://docs2.yoyogames.com/index.html?page=source/_build/2_interface/1_editors/objects.html

Thanks for your fast reply ^^ I will make some research about that and let you know if the problem persist :) thanks.
 
M

maranpis

Guest
Okay, the issue here is that collisions are based on the COLLISION MASK, which in turn is based on the sprite currently assigned to the instance. So, if you change the sprite or you change the scale or rotation, you also change the collision mask and so it can get "stuck" in other instances around it. The solution to your problem is to create a special rectangular mask sprite (the same size as the collision mask of the sprite that works for you), and then assign that as the instance's MASK INDEX. The mask_index is a special sprite that won't be drawn but will be used instead ONLY for collisions. In this way you can draw whatever you want as the instance sprite, and collisions will always be based off of the mask rather than the sprite.

See the section on the collision mask here: http://docs2.yoyogames.com/index.html?page=source/_build/2_interface/1_editors/objects.html
Now is working fine, thanks for your help :)
 

Roderick

Member
The solution to your problem is to create a special rectangular mask sprite (the same size as the collision mask of the sprite that works for you), and then assign that as the instance's MASK INDEX. The mask_index is a special sprite that won't be drawn but will be used instead ONLY for collisions.
That's neat! I've been doing that manually by just giving things a one frame square sprite, and putting the animations in the draw event. Does what you're talking about exist in 1.4, or should I keep doing it my way until I upgrade?
 
Top