Mounting a GUI / 2dStaticSprite *above* a rotating object?
by Brooks Talley · in Torque Game Builder · 11/19/2009 (2:48 pm) · 3 replies
Hi, everyone. I really appreciate the value of the community here.
I'm struggling with mounting a basic hit point display above an object that's capable of rotating, without having my hit point display rotate all over the place when the object rotates. I have to think I'm just missing something obvious.
I'm doing something like:
I've tried setting position in the t2dstaticsprite and using "0 0" for the mount point, but that produces the same result: as soon as the object rotates, the hit point bar rotates around the object as well.
Any way to mount something at a fixed position relative to an object and to have it ignore the object's rotation? Or am I barking up the wrong tree altogether with mount?
Thanks!
I'm struggling with mounting a basic hit point display above an object that's capable of rotating, without having my hit point display rotate all over the place when the object rotates. I have to think I'm just missing something obvious.
I'm doing something like:
%hpBar = new t2dStaticSprite(hpbar) {
scenegraph = %scene;
imageMap = PlayerHitPointBarImageMap;
size = "6.0 3.0";
}
%hpBar.mount(%obj, "0 -3", 0, false, true, true);I've tried setting position in the t2dstaticsprite and using "0 0" for the mount point, but that produces the same result: as soon as the object rotates, the hit point bar rotates around the object as well.
Any way to mount something at a fixed position relative to an object and to have it ignore the object's rotation? Or am I barking up the wrong tree altogether with mount?
Thanks!
#2
I did catch my mistake with the params to mount, but it's kind of moot --%trackRotation only affects whether the mounted item itself rotates on its own axis to match its parent object's rotation. It's still always displaced. So you can have a gui for an object that both goes both underneath the and turns upside down, if you want.
The other approach I thought of, but decided against because it's mathy enough to be a paid, would be to have the hitpoint bar recalculate its position and change its link point on the parent object in relation to the parent object's rotation. Should work, but there's going to be trig involved, and I get tired of flipping sin/cos/tan/atan and positive and negative signs until it works :)
Thanks again!
11/19/2009 (6:54 pm)
Cool, thanks for that. I went with that approach. It seems a little inelegant, but it works :)I did catch my mistake with the params to mount, but it's kind of moot --%trackRotation only affects whether the mounted item itself rotates on its own axis to match its parent object's rotation. It's still always displaced. So you can have a gui for an object that both goes both underneath the and turns upside down, if you want.
The other approach I thought of, but decided against because it's mathy enough to be a paid, would be to have the hitpoint bar recalculate its position and change its link point on the parent object in relation to the parent object's rotation. Should work, but there's going to be trig involved, and I get tired of flipping sin/cos/tan/atan and positive and negative signs until it works :)
Thanks again!
#3
11/20/2009 (6:31 am)
On top of that, if you tried to re-calculate the position of mounted object, don't forget that you have to unmount-remount that object again and again... and that could be a serious performance issue.
Milan Rancic
obj.invisibleMount = new t2dSceneObject()
Then i mount health bar to THAT invisible object.
Also, if you look at definition of mount() function it sais this:
mount(%object, %offsetX, %offsetY, %force, %trackRotation, %sendToMount, %ownedByMount, %inheritAttributes);
And you set %trackRotation to true, since torque treats your "0 -3" string as one paremeter (%offsetX).
This file will be usefull to you:
webclass.superquest.net/gamemaker-projects/Vickie%20Brown/documentation/referenc...
Keep it open in background at all times.