1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML Fail in programming a flip of sprite

Discussion in 'Programming' started by Loïc Mouton, Nov 6, 2019.

  1. Loïc Mouton

    Loïc Mouton Member

    Joined:
    Sep 13, 2019
    Posts:
    9
    Hi community !

    I'm french and it's my first post here so i'm sorry for my english mistake.

    I've a problem with my code for flip my character in my first platformer game.

    Here's my code for flip :

    Code:
    if (hspd != 0)
    {
        image_xscale = sign(hspd)
    }
    My normal character :

    upload_2019-11-6_17-40-4.png

    and when i want to flip :

    upload_2019-11-6_17-41-2.png

    The ratio is destroyed xD

    Can someone tell me how can i fix that ?

    Thanks everyone ^^

    Loïc Mouton
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,267
    Save your characters default scale in a variable in the Create Event. Then use that value * sign(hspd) when setting the image_xscale.
     
  3. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,707
    There is no way for sign to return anything but -1, 0 or 1. Are you sure that the code you posted is causing this? Are you changing the scaling of this sprite anywhere else?
     
  4. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    65
    I'm assuming that your default image scale is smaller than 1 and on the stretched image it's got -1 x and something like .5 y
     
  5. Loïc Mouton

    Loïc Mouton Member

    Joined:
    Sep 13, 2019
    Posts:
    9
    I've used the solutions of IndianaBones and it's work better ! Thanks you all for your answer !

    Here is the code for those who have the same problem in the future :

    In create event :
    Code:
    scale_x = image_xscale
    In step event :
    Code:
    if (hspd != 0)
    {
        image_xscale = scale_x *sign(hspd)
    }
     
    IndianaBones likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice