GameMaker the size of my sprite changes when i flip the image - can anyone help out?

i_am_virgo

Member
context: so i'm currently working on a princess peach themed game as a birthday gift for my sister, and i am quite new to programming. i've been following the general Shaun Spalding platformer tutorial to get a feel for GML, and i've run into a problem when trying to flip the sprite when the direction of movement changes. by using the image_xscale variable combined with sign to return info and any given key-check or hsp variable, that should flip the sprite's image horizontally, if i'm correct.

the problem: by using this code (screenshots included), my sprite scale changes so that poor little peach looks about half her width than before. essentially, the moment i use either directional button, her scale changes. i've fiddled around with all of the object's code from top to bottom for a few hours and i haven't figured out why.

i'm very new to GML and if anyone has any advice, it would be greatly appreciated!

--

photo 1: the general animation code
photo 2: peach's normal sprite
photo 3: when homegirl tries to move and loses 50 pounds
 

Attachments

rytan451

Member
It looks like your princess starts at image_xscale = 2, and when you turn her around, she becomes image_xscale = -1.

Instead of setting image_xscale to a fixed number, consider instead setting it to, for example, -image_xscale, to flip it.
 

woods

Member
image_xscale = sign(hsp)

i get that this makes the sprite flip when changing direction +/-


is one direction moving faster than the other? ie.. left spd=1 right spd =2
(wouldnt that would make the sprite stretch all wonky?)

btw is easier to help if you post your code in tags instead of screenshots
 

i_am_virgo

Member
image_xscale = sign(hsp)

i get that this makes the sprite flip when changing direction +/-


is one direction moving faster than the other? ie.. left spd=1 right spd =2
(wouldnt that would make the sprite stretch all wonky?)

btw is easier to help if you post your code in tags instead of screenshots
thank you!! both directions are moving at the same speed. i'll paste the code below
 

i_am_virgo

Member
this is excluding th rest of the code because i've mostly narrowed it down and that's a lot of reading

GML:
//Animation
if(!place_meeting(x,y+1,object1))
{
    sprite_index = spr_peachjump;
    image_speed = 0;
    if(sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 1;
    
    if(hsp == 0)
    {
        sprite_index = spr_peach;
    }
    else
    {
        sprite_index = spr_peach;
    
    }
}

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

woods

Member
is there any other reference to image_xscale or image_yscale?

im with rytan... setting image_xscale to -image_xscale should fix the situation

Code:
    if(hsp != 0)
    {
    image_xscale = -image_xscale;
    }
 

i_am_virgo

Member
i'm testing the code right now and cleaning up other minor errors in the process. there's one other problem i've run into - peach does turn and move as she's supposed to, but she's sort of flickering(?) in a sense. it looks like her frame rate is at around 64 but all the sprite frame rates are 5 or lower. i'm working on this now, but you've solved a big part of the problem. thank you! and if you have any suggestions about the new thing, it'd be greaty appreciated! :)
 

i_am_virgo

Member
here's the code that i'm working with now

GML:
//Animation
if(!place_meeting(x,y+1,object1))
{
    sprite_index = spr_peachjump;
    image_speed = 0;
    if(sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 1;
    
    if(hsp == 0)
    {
        sprite_index = spr_peach;
    }
    else
    {
        sprite_index = spr_peachwalk_r;
    
    }
    
}

    if(hsp != 0)
    {
    image_xscale = -image_xscale;
    }
the only screenshots i've been able to take of the problem have shown up as one of her frames, so i know it's a frame rate problem. i'm looking into it rn!
 

i_am_virgo

Member
i'm attempting to test it out with another else branch to tell it specifically when to use the right and left-facing sprites, but it's coming up with a syntax error. any thoughts?
 

Roldy

Member
For sanity just slam the image_yscale at the same time so you know what it is:


GML:
    if(hsp < 0)
    {
        image_xscale = -1.0;
        image_yscale = 1.0;
    } else {
        image_xscale = 1.0;
        image_yscale = 1.0;   
    }
See what happens
 
Just so you know, this line was causing the flickering:
Code:
if(hsp != 0)
    {
    image_xscale = -image_xscale;
    }
Every frame you are moving (so 60 times a second), the computer flips image_xscale. First frame image_xscale is 1, so it gets changed to -1, then on the next frame, image_xscale is -1, so it gets changed to 1, then on the next frame, image_xscale is 1, so it gets changed to -1, repeat for however long you are moving.

If you are changing image_xscale to anything but 1 anywhere and/or setting image_yscale to image_xscale at any point, then you'll run into problems with the code you posted originally, but as far as I can see, it should work fine if you are not doing any of those things I just mentioned. So, while you've fixed it already, you might want to run a find for image_xscale and then for image_yscale and see what you are actually doing with them everywhere in the code.
 
Top