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°.
float delta = 0.0f, lastx = 0.0f, lasta = 0.0f, currx = 0.0f, gridx = 16.0f;
while (Core.LoopAGK())
{
if (Agk.IsRawMouseLeftPressed()) // the same as if(Agk.GetRawMouseLeftPressed() == 1)
{
lastx = Agk.GetRawMouseX();
lasta = Agk.GetSpriteAngle(1);
}
if (Agk.IsRawMouseLeftDown()) // the same as if(Agk.GetRawMouseLeftState() == 1)
{
currx = Agk.GetRawMouseX();
delta = Agk.Floor((currx - lastx) / gridx);
Agk.SetSpriteAngle(1, lasta + delta * 15.0f); // I use here an angle grid of 15 degrees. use other values if you want ;)
}
Agk.Sync();
}
Share your knowledge. It\'s a way to achieve immortality.
(Tenzin Gyatso)