Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Rotate Sprite By Mouse Starting Up From Sprite's Current Angle

Author
Message
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 26th Dec 2018 21:39
Hello forum,

I want to rotate a sprite by mouse on X axis (mouse) and I want the rotation to start from where the sprite's angle is before I click to rotate it. Right now, when I click to rotate the sprite, it instantly adds the cursor's position.



Thank you!
www.alexmatei.com
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 27th Dec 2018 12:45
You need the mouse movement. So the difference from the previous position of the mouse pointer and add the value to the current angle of your sprite.

Here is an example.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 27th Dec 2018 16:17
Hello MadBit,

Thank you very much for the example! It works absolutely amazing!

How can I integrate the value cellx from my code? It's for the grid system. I assume I cannot put just a simple " + " there.
www.alexmatei.com
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 28th Dec 2018 06:44
It depends on what you want to achieve with the grid in respect to rotating the sprite. Since I assume that your grid has slightly higher values - I think 16 or 32, the example shown cannot be used that way. Because the movement of the mouse is too small.
The solution would be to remember the last mouse position and last angle of the sprite when pressing the mouse button. From there the calculations can take place. But the rotation would be very slow. Or you can use a kind of grid for the angles.
In the example below I use a grid of 15°.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 28th Dec 2018 12:40
Exactly what I wanted! I should start learning these equations. Obviously I will get hit by them in the future also.

Thank you a million!
www.alexmatei.com

Login to post a reply

Server time is: 2024-03-28 08:15:05
Your offset time is: 2024-03-28 08:15:05