Game Development Community

resizing a mounted object

by Justin Mosiman · in Torque Game Builder · 03/15/2009 (9:37 am) · 6 replies

Hello,

I have a health bar and it has two components: the fill which is resized based on the amount of health a character has and the frame which the fill attaches to.

When the object it is attached to takes damaged, the fill is being resized and positioned correctly whenever it isn't mounted to the frame. As soon as I mount it, the fill is always repositioned to be in the center of the frame, when I want it to be more towards bottom. If I don't have the fill mounted to the frame than it gets positioned correctly. The image below should help if my explanation wasn't clear.

www.opsive.com/images/healthMount.png
How do I get it not to recenter the fill when it is mounted? The code that I am using to resize is:
function HealthBarBehavior::setFillPercent(%this, %fillPercent)
{
	%this.currentHeight = %this.maxHeight * %fillPercent;
	%this.Owner.setSize(%this.Owner.getSizeX() SPC %this.currentHeight);
	%this.Owner.setPosition(%this.Owner.getPositionX() SPC (%this.bottomPosition - %this.currentHeight/2));
}

Thanks,
Justin

#1
03/15/2009 (3:15 pm)
change the mount points to the bottom of your health bar and the bottom of the container
#2
03/15/2009 (3:56 pm)
What values should I have for the mount points? Here is what I have, which have the mount at the bottom.

new t2dStaticSprite() {
      imageMap = "health_frameImageMap";
      frame = "0";
      canSaveDynamicFields = "1";
      Position = "47.063 0.743";
      size = "4.125 16.000";
      LinkPoints = "0.000 1.000";
         mountID = "9";
   };
   new t2dStaticSprite() {
      imageMap = "health_fillImageMap";
      frame = "0";
      canSaveDynamicFields = "1";
      Position = "47.063 0.743";
      size = "3.004 14.805";
      Layer = "1";
      LinkPoints = "0 1.000";
      MountOwned = "0";
      MountInheritAttributes = "0";
         mountID = "10";
         mountToID = "9";
   };
#3
03/15/2009 (5:33 pm)
%this.bottomPosition - %this.currentHeight/2 u dont need to update the bottomposition in this way this is setting say if bottom = 3 , 3-(100/2)=-47 so your bottom position is getting set so its setting the y and since your link points are at the bottom it is moving the health bars up down position
#4
03/15/2009 (5:34 pm)
%this.Owner.setSize(%this.Owner.getSizeX() SPC %this.currentHeight);
see u already set the health bars size here <<<<<<<<
#5
03/15/2009 (7:29 pm)
I've commented out setSize, but it is still repositioning to the center. I've noticed that when I open the link points up in the frame (within the game builder), there a linkpoint in the center even though it isn't in the code. If I delete it, it says that it is in use, and asks me if I want to dismount children and delete linkpoint. How is there one in the center? Is it created automatically? How can I not use it?
#6
03/16/2009 (3:20 pm)
Does anybody have any other ideas? I have gotten it to sort of work by resetting the link point after each damage, but this doesn't seem like the right way of doing it. If I want to apply animation of the health going down so if I have to modify the link point it's not going to be easy.

But here is my linkpoint code:
%this.currentHeight = %this.maxHeight * %fillPercent;
	%this.Owner.setSize(%this.Owner.getSizeX() SPC %this.currentHeight);
	%parent = %this.Owner.getMountedParent();
	if(%parent.getLinkCount() != 1){
		error("Health bar frame must only contain one link point.");
		return;
	}
	%parent.setLinkPoint(1,0.0,%fillPercent);