Legacy GM [SOLVED] Rotation with lengthdir, origin, one instance

G'day G'day!

I'm trying to rotate an object's sprite around its sprite origin (which I have set to be at the center of the sprite), but after I have first re-positioned it with lengthdir.

The sprite is drawn correctly at the new location with the lengthdir functions, but the point (axis?) of rotation is always the object's X and Y coordinates, which is wrong.

I have thought about first drawing the sprite correctly rotated to a surface, and then drawing that surface to the new position with lengthdir, but before I try that, is there any way to specify a new point of axis?
 
Last edited:
This code changes the image angle of the sprite:
Code:
mousedir  = point_direction(x, y, mouse_x, mouse_y);
image_angle = mousedir;
This code re-positions the sprite where I want it to be:
Code:
draw_x  = x + lengthdir_x(50, image_angle);
draw_y  = y + lengthdir_y(50, image_angle);
draw_sprite_ext(sprite_test, 0, draw_x, draw_y, 1, 1, image_angle, image_blend, image_alpha);
The sprite is correctly re-positioned to the new draw_x and new draw_y values, but the axis of rotation remains the object's x and y.
 
Here is an image to clearly show what's needed:



P.S. I can achieve this if I use a completely separate object, say, OBJECT B but I want to do this with ONE object, if possible
 
Here is an image to clearly show what's needed:



P.S. I can achieve this if I use a completely separate object, say, OBJECT B but I want to do this with ONE object, if possible
I don't use lengthdir_y or lengthdir_x, i just handle things with dcos and dsin.
You might want to draw have y subtract the value, since y increases from the top and not from the bottom:
Code:
draw_y  = y - lengthdir_y(50, image_angle);
Edit: the image isn't working, so I am not sure if I am understanding your question correctly.
 
You mean that the rotation of the sprite is still zero, right?

The code you posted doesn't explain the problem you are having.

Do you have duplicate code elsewhere that might be conflicting with this code? Perhaps a version where lengthdir remains, but where the actual draw function is different?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Code:
draw_x  = x + lengthdir_x(50, image_angle);
draw_y  = y + lengthdir_y(50, image_angle);
var  _ang  = point_direction(draw_x, draw_y, mouse_x, mouse_y);
draw_sprite_ext(sprite_test, 0, draw_x, draw_y, 1, 1, _ang, image_blend, image_alpha);
:)
 
Hi flyingsaucerinvasion, I hope you are well. Thanks for writing in mate!
Nocturne, that's solved it. Bloody hell. I probably would never have realised the importance of interchanging image_angle and _ang.
Thank you very much.

By the way, is my example image working? (I can see it, but Online_Handle reported that it didn't display)
 
Hi flyingsaucerinvasion, I hope you are well. Thanks for writing in mate!
Nocturne, that's solved it. Bloody hell. I probably would never have realised the importance of interchanging image_angle and _ang.
Thank you very much.

By the way, is my example image working? (I can see it, but Online_Handle reported that it didn't display)
Forgot that I was using my work computer when I viewed that link. The domain is blocked for me. The image definitely works when I am not on their network. Sorry about that. Also, yea - that image woulda cleared things up :p
 
Top