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:
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!
There's no reason why a code which worked in 3.6.1 would not work in 3.6.2. This must be a engine's bug.
Here's a fixed 3.6.2 engine, please try if it works for you:
https://www.dropbox.com/scl/fi/r2gddt30ougctlouf7ega/acwin-3.6.2-fixspriterotate.zip?rlkey=45pnuqawws1ffj5emxbqfql10&st=s26u43ti&dl=0
(you may replace it inside 3.6.2 Editor program files)
Yes, now that I think about it, it does make sense that code working in 3.6.1 should also work in 3.6.2. It's great to know there was nothing wrong with how my code worked.
The fixed engine runs perfectly — the sprite now rotates correctly again.
Thank you so much!