Setting Anchor Point (Local Center) of Sprite for Rotation
by Brian Szatkowski · in Torque 2D Beginner · 03/27/2013 (9:46 am) · 5 replies
Hi All;
I've been toying around with getting a static object to rotate when needed by +/- X degrees. However, I've come across a stumbling block that I hope is just an oversight on my part.
How do I modify the anchor point (or local center) of a Sprite so that when I use setAngle(), the object is rotated about its anchor point as opposed to its world center?
I am able to simulate what I want using the physics approach (since I can quite readily add a fixture and offset its position to effectively set a new local center for a dynamic Sprite) but realized there is no need for physics for accomplishing what I want. As I do intend on adding some significant physics-influenced objects to my scene later, I want to save as much calculation as possible by eliminating things from the pipeline that do not need to rely on physics to do simple translations or orientation transforms.
Update
If there is no inherent way to do what I want (i.e. some method I've overlooked), I suppose I could create a CompositeSprite, offsetting the actual static sprite such that when I rotate the CompositeSprite about its anchor, the static child is rotated as I so desire, simulating it having a modified local center.
Any thoughts?
Thank you,
Brian
I've been toying around with getting a static object to rotate when needed by +/- X degrees. However, I've come across a stumbling block that I hope is just an oversight on my part.
How do I modify the anchor point (or local center) of a Sprite so that when I use setAngle(), the object is rotated about its anchor point as opposed to its world center?
I am able to simulate what I want using the physics approach (since I can quite readily add a fixture and offset its position to effectively set a new local center for a dynamic Sprite) but realized there is no need for physics for accomplishing what I want. As I do intend on adding some significant physics-influenced objects to my scene later, I want to save as much calculation as possible by eliminating things from the pipeline that do not need to rely on physics to do simple translations or orientation transforms.
Update
If there is no inherent way to do what I want (i.e. some method I've overlooked), I suppose I could create a CompositeSprite, offsetting the actual static sprite such that when I rotate the CompositeSprite about its anchor, the static child is rotated as I so desire, simulating it having a modified local center.
Any thoughts?
Thank you,
Brian
About the author
#2
03/27/2013 (11:20 am)
Thanks for your feedback and confirming what I found. I guess I'll need to take the CompositeSprite route, then.
#3
03/27/2013 (11:43 am)
It's not that difficult to add as a feature but so far nobody has requested it.
#4
03/27/2013 (11:49 am)
^ Requesting. ;)
#5
03/27/2013 (11:50 am)
Of course. :)
Torque Owner William Hilke