how to change the sprite frame, to point to the mouse

For questions about using Classic.

Post » Wed Jun 01, 2011 9:36 am

does anybody know how to set the frame number to the angle of the mouse coordinates from a sprite object... sorry if im not making any sense, i've been up all night and now its over 12pm.

What i want to do, is have my player character point his gun towards the mouse regardless of what direction he is moving.
some unfinished sprites :P


its easy to do in game maker "point_direction(x,y,mouse_x,mouse_y) /45", but i've run into some different problems there that would be so easy to do in Construct :?
B
1
G
1
Posts: 1
Reputation: 427

Post » Wed Jun 01, 2011 3:56 pm

I think what you're looking for is set the animation frame to: angle(.x, .y, mousex, mousey)/45

You might need to round it, though, I'm not sure. If so, try this: round(angle(.x, .y, mousex, mousey)/45)
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Thu Jun 02, 2011 6:55 pm

If the animation frames start with right then go clockwise this formula will work:
round(angle(.x, .y, mousex, mousey)/45)%8+1

You can also setup animation angles so that when you point an object to a point construct will automatically select the closest angle.

Here is two ways to do it:
http://dl.dropbox.com/u/5426011/examples5/lookat.cap
made in cc1.2
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests