Image_Flip - Sticker-book

T

Teslatronik

Guest
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
Code:
///imagescale

//scale
    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;
       }
      
//limits
        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

//flip
    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.
 

chance

predictably random
Forum Staff
Moderator
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.
 

GMWolf

aka fel666
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:
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.
 
T

Teslatronik

Guest
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 by a moderator:
Top