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

Problems with flipping sprites

Ache

Member
I'm having problems flipping my player object's sprites. Technically, it does flip the sprites, but the sprites are compressed (shown in the picture) Screenshot 2021-12-02 000551.png

Create event for the player object
GML:
image_xscale = image_xscale * 3;
image_yscale = image_yscale * 3;

hsp = 0;
vsp = 0;
grv = 0.5;
walksp = 4;
Step event for player object
GML:
//input
keyleft = keyboard_check(vk_left) or keyboard_check(ord("A"));
keyright = keyboard_check(vk_right) or keyboard_check(ord("D"));
keyjump = keyboard_check(vk_up) or keyboard_check(ord("W"));

//movement
var move = keyright - keyleft;

hsp = move * walksp;
vsp = vsp + grv;

//jumping
if place_meeting(x, y + 1, obj_wall) and keyjump
{
    vsp = -10;    
}

////collisions
//horizotal collision
if place_meeting(x + hsp, y, obj_wall)
{
    while(!place_meeting(x + sign(hsp), y, obj_wall))
    {
        x += sign(hsp) 
    }
    hsp = 0    
}
//vertical collision
if place_meeting(x, y + vsp, obj_wall)
{
    while(!place_meeting(x, y + sign(vsp), obj_wall))
    {
        y += sign(vsp) 
    }
    vsp = 0    
}
x += hsp;
y += vsp;

//animation
if !place_meeting(x, y + 1, obj_wall)
{
    sprite_index = spr_player_jump;
    if sign(vsp) > 0
    {
        image_index = 1;
    }
    else
    {
        image_index = 0;    
    }
}
else
{
    if hsp == 0
    {
        sprite_index = spr_player_idle;    
    }
    else
    {
        sprite_index = spr_player_move;    
    }
}
if hsp != 0
{
    image_xscale = sign(hsp);    
}
 
You stretch the sprite 3 times in the create event, but in this piece of code, it'll set the x_scale to either +1 or -1
Just multiply that thing by 3, and you'll be allright.

GML:
if hsp != 0
{
    image_xscale = sign(hsp);   
}
 

Nidoking

Member
image_xscale = image_xscale * 3;
image_yscale = image_yscale * 3;
This is stretching your sprite. Your sprite is never compressed, but because it's stretched to start with, you expect it to be three times as wide and three times as tall.

image_xscale = sign(hsp);
This is not stretching your sprite in the same way. The image_xscale variable doesn't hold the notion of being multiplied by three, nor has the sprite resource itself been altered in any way. You have to do the multiplication yourself each time you want three times a value, or you need to modify the sprite resource to be the size you want.
 

Ache

Member
You stretch the sprite 3 times in the create event, but in this piece of code, it'll set the x_scale to either +1 or -1
Just multiply that thing by 3, and you'll be allright.

GML:
if hsp != 0
{
    image_xscale = sign(hsp);  
}
Wow that was a lot simpler than I thought it was. Thanks for the help!
 
Top