Game Development Community

Sprite setPivotPoint()

by Tim Doty · in Torque Game Builder · 03/06/2005 (1:24 pm) · 9 replies

Unless I'm missing something (entirely possible) you can't set the pivot point for (at least) staticsprites. There is a setPivotPoint() function for particle effects and I decided to try it for grins on the sprite (hoping it existed undocumented) but all I got was an error.

What am I missing? Or can this be added?

#1
03/06/2005 (11:08 pm)
There is a whole thread on this here www.garagegames.com/mg/forums/result.thread.php?qt=26502. The short answer is "no, but they are looking at this going forward." For now, you need to have the center your sprite image at your desired pivot point... this means that your sprite may need to be larger (waste a little video memory).
#2
03/06/2005 (11:53 pm)
As Melv has mentioned, you can "fake" arbitrary rotation points without doing the "make the sprite larger" dealie-- By mounting one object to another. For example, let's assume a hammer sprite, that you want to smash something with. If you just make the sprite normally, then try to rotate it, it will rotate around the exact sprite center -- which in this case would be somwhere around halfway up the handle. Not what we want.

So, you make a new fxSceneObject2D, set its size to something moderate, and don't set an image for it so that it is invisible -- then mount the hammer sprite onto it, at the top. Line up the bottom of the hammer with the center of your newly-made object. Set the mounted hammer to track rotation, and boom, when you rotate the parent object, the hammer will tip as if its rotating along the base.

UPDATE: Hmm, maybe this will explain it better:

www.gapingwolf.com/hammerexample.gif
#3
03/07/2005 (5:51 am)
Thanks for the replies! I'd looked through the thread topics but managed to miss the original one. The idea of making the sprites larger had occured to me, but I don't like it very much. Using an invisible sprite as intermediate is more appealing.
#4
03/12/2005 (12:28 pm)
Setting the Registration point should be implemented. Enlarging the sprite or using an invisible sprite is horrendous. BTW Targa files can store the registration point within the file itself.
#5
03/13/2005 (1:35 am)
Horrendous is such a strong word. ;)

Sorry if this causes you problems at the moment. It's already on the list of things to do so you won't be doing it forever.

- Melv.
#6
03/13/2005 (2:58 am)
Yes, I overreacted, horrendous really is a too strong.
I should have written "an abomination".




;)
#7
03/13/2005 (4:39 am)
LOL!

Message received and understood. ;)

- Melv.
#8
05/09/2005 (1:56 pm)
I noticed some code on the C++ side for managing the pivot point. Consider this code from "fxSceneObject2D.cc", under ::calculateSpatials:

Quote: // Calculate Pivot Offset.
fxVector2D size = getSize();
fxVector2D halfSize = size/2.0f;
fxVector2D pivotOffset = -halfSize;

Does that seem like a good place to change where the pivot point is? Or are there other locations where the C++ code assumes a mid-point?

steve
#9
05/10/2005 (12:01 am)
Stephen,

There's no issue with doing the minor work to change the pivot-point but it has impacts on the rigid-body physics routines.

Just finiishing some other work at the moment, then I can get this one off the list.

- Melv.