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

changing object frame by cursor

V

ventyl

Guest
Hi, could someone write or help me with code about changing object frame by cursor?;D
I mean i want to change frame of my object after place the cursor in a given place.
for example: when i give my cursor above my object (for 45° to 135° (like on protractor ;b)(4o.png)) his frame will change for frame numer e.g. 4 ..etc...like on attached png
i believe that is understandable ;dd
and sory for trouble, it's probably ridiculous, i'm begginer and maybe too young for play with gm2 but quarantine is taking its toll ;bb
and if you have better solution for this i'll enjoy it:D (i don't wanna do this like image_angle with hands and head separate)
GML
THX
 

Attachments

kburkhart84

Firehammer Games
I would break it up into little pieces.

1. Figure out how to get the cursor position x/y.
2. Use point_direction() function to get the direction from the x/y of the player object to the cursor. If the cursor is directly to the right, you will get direction 0. If directly above, you get 90.
3. Use the result of number 2 with some if statements, like if the angle is over 45 and under 135, you know to point up, and so on.
4. Change the image_index accordingly.

Note that this assumes your sprite is not going to have any animation, because the animation itself is the four directions. If you had 4 different animated sprites, you would set the sprite_index to the right one instead of setting a single frame.
 
Top