Image_Flip - Sticker-book

Discussion in 'Programming' started by Teslatronik, Dec 11, 2016.

  1. Teslatronik

    Teslatronik Member

    Aug 11, 2016
    Hello All, I'm making what i thought would be a rather simple drag and drop style Dinosaur "sticker book" for my son.. but the problem comes when i try to Flip the sprite while having a scale limitation.

    i want to be able to press a key and have the sprite "flip" and stay flipped until the key is pressed again.
    Any help is appreciated.. here is the code i have so far..(it instantly un-flips due to the limits i set)

    ///// Step Event -of the Dino object
        if(position_meeting(mouse_x,mouse_y,self)) and mouse_wheel_down()
           image_xscale -= 0.1;
           image_yscale -= 0.1;
        if(position_meeting(mouse_x,mouse_y,self)) and mouse_wheel_up()
           image_xscale += 0.1;
           image_yscale += 0.1;
            if image_xscale < 0.2 then image_xscale = 0.2
            if image_xscale > 2   then image_xscale = 2
            if image_yscale < 0.2 then image_yscale = 0.2
            if image_yscale > 2   then image_yscale = 2
        if(position_meeting(mouse_x,mouse_y,self))and keyboard_check_pressed(ord("F"))
           image_xscale = -image_xscale     
    //change image_index
        if(position_meeting(mouse_x,mouse_y,self))and  keyboard_check_pressed(vk_right)
            image_index[0] += 1
        if(position_meeting(mouse_x,mouse_y,self))and  keyboard_check_pressed(vk_left)
            image_index[0] -= 1
    Thanks, Alan.
  2. chance

    chance predictably random Forum Staff Moderator

    Apr 22, 2016
    Different ways you could handle this. One way is to define a "scale" variable, and a "sign" variable. Then, rather than operate on image_xscale directly, have your //scale, //limits, and //flip code operate on the "scale" and "sign" variables.

    The "scale" variable is for both x and y scales, and is always positive. The "sign" variable toggles between -1 and +1.

    Then after that's done, set image_xscale = scale*sign. (but watch out for reserved keywords, of course.)

    No reason to write any code here. I'm sure you get the idea.
  3. GMWolf

    GMWolf aka fel666

    Jun 21, 2016
    You can keep your current code, but do a couple sign and abs tricks.
    Its a bit hard to describe it, so ill just give you code:
    if abs(image_xscale) < 0.2 then image_xscale = 0.2 * sign(image_xscale)
    if abs(image_xscale) > 2   then image_xscale = 2 * sign(image_xscale)
    Do the same for the y axis.

    Now that I write it down, its not too complicated actually...

    If you need any help with the abs and sign functions, and how this works, please ask :) also, if this doesn't work (there's a good chance, just came up with it...), please tell me. Its probably a small mistake.
  4. Teslatronik

    Teslatronik Member

    Aug 11, 2016
    Thankyou @ chance.
    @Fel666 Thanks your code works as an alternative to my limit code, but did not solve the issue at hand ( but i still replaced mine with your's(ty) , i have fixed it via a true/false var with diff code in each variable as suggested by chance.. thank you both for your time.
    Last edited: Dec 11, 2016

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