Hi!
As I mentioned in the title, in one of my games I have a windmill with blades that rotate around their own pivot point. To achieve this, I tried to coded a small void in version 3.6.1, which I call from a repeatedly execute. In it, I create a dynamic sprite and rotate it by a certain angle.
However, after upgrading from version 3.6.1 to 3.6.2, I noticed that the blades no longer rotates — instead, they just "tremble" in place without actually moving.
Here's my code:
Code: ags
I guess there's something incorrect that I'm not seeing. So the question is: what could be wrong in my code that worked fine in 3.6.1 but not in 3.6.2?
Thanks a lot in advance!
As I mentioned in the title, in one of my games I have a windmill with blades that rotate around their own pivot point. To achieve this, I tried to coded a small void in version 3.6.1, which I call from a repeatedly execute. In it, I create a dynamic sprite and rotate it by a certain angle.
However, after upgrading from version 3.6.1 to 3.6.2, I noticed that the blades no longer rotates — instead, they just "tremble" in place without actually moving.
Here's my code:
DynamicSprite *aspasSprite;
int angle = 0;
int aspasX = 485, aspasY = 452; // lower left corner coords (angle 0). With "aspas" I mean "blades".
float px = 158.5;
float py = 158.5; // sprite's pivot cords
void Aspas(){
angle = (angle + 1) % 360;
// Here I set the sprite and store dimensions
aspasSprite = DynamicSprite.CreateFromExistingSprite(421);
int w = aspasSprite.Width;
int h = aspasSprite.Height;
// rotate if it's necessary
if (angle > 0) aspasSprite.Rotate (angle);
oAspas.Graphic = aspasSprite.Graphic;
// Here I calculate the sprite dimension change offset
float xOff = IntToFloat(w - aspasSprite.Width) / 2.0;
float yOff = IntToFloat(aspasSprite.Height - h) / 2.0;
// Here I calculate vector from pivot to center
float vx = IntToFloat(w) / 2.0 - px;
float vy = IntToFloat(h) / 2.0 - py;
// rotate vector
float rad = Maths.DegreesToRadians (IntToFloat (angle));
float cos = Maths.Cos(rad);
float sin = Maths.Sin(rad);
float vrx = vx * cos - vy * sin;
float vry = vx * sin + vy * cos;
oAspas.X = aspasX + FloatToInt(xOff - vx + vrx, eRoundNearest);
oAspas.Y = aspasY + FloatToInt(yOff - vy + vry, eRoundNearest);
}
I guess there's something incorrect that I'm not seeing. So the question is: what could be wrong in my code that worked fine in 3.6.1 but not in 3.6.2?
Thanks a lot in advance!