Problem using t2dSceneObject as a health bar
by Richard Skala · in iTorque 2D · 05/18/2010 (8:12 pm) · 6 replies
I am using a t2dSceneObject as a Health Bar, and it works fine, except for one important issue.
When resizing the t2dSceneObject health bar (when the user loses 'health'), it shrinks towards the middle, which is correct since the "position" is the center of the object. So, to compensate, in the same frame, I move the object downwards by half the amount it was resized, so it is positioned correctly.
The problem is that the t2dSceneObject doesn't seem to update fast enough, causing the user being able to see the health bar shrinking and moving down very quickly.
I would like the object to resize and reposition immediately to avoid this issue. Is there some way I can force a draw update or something on the t2dSceneObject? Is there some other solution I might be missing?
Thanks for any assistance.
When resizing the t2dSceneObject health bar (when the user loses 'health'), it shrinks towards the middle, which is correct since the "position" is the center of the object. So, to compensate, in the same frame, I move the object downwards by half the amount it was resized, so it is positioned correctly.
The problem is that the t2dSceneObject doesn't seem to update fast enough, causing the user being able to see the health bar shrinking and moving down very quickly.
I would like the object to resize and reposition immediately to avoid this issue. Is there some way I can force a draw update or something on the t2dSceneObject? Is there some other solution I might be missing?
Thanks for any assistance.
About the author
Founded in 2009, Pixel Vandals Inc. is focused on bringing fun, fresh, and new ideas to the iPhone. www.pixelvandals.com www.pixelvandals.com/vineking
#2
05/19/2010 (1:10 am)
I appreciate the input, but I don't think that will be accurate enough, as the value can be any float value between 0.0f and 100.0f. I was thinking that perhaps I need to use a 'GuiControl' instead of a 't2dSceneObject'. Unfortunately, information about 'GuiControl' objects seems kind of scarce, so I don't really know much about them.
#3
GUI
05/19/2010 (1:44 am)
Game code// %power = life amount. %width = %power * 2; // or what ever size u want the bar. %height = getWord(lifeBar.extent, 1); lifeBar.setExtent(%width, %height); return;
GUI
new GuiBitmapCtrl(lifebar) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "3 2";
Extent = "197 25";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/solidcolor.png";
wrap = "0";
useSourceRect = "0";
sourceRect = "0 0 0 0";
};
#4
05/19/2010 (5:38 am)
ok, this is a good start -- I have the object created through script, and the object is found using Sim::findObject(). I'm using your code exactly how it is above, except I changed the bitmap name, of course. However, it doesn't show up on screen. Any ideas why that might be?
#5
2) the size does not have to be full size, it could be size 2x2. it gets resized / stretched from the code.
3) proper coding for bitmap should be ...
bitmap = "~/data/images/green";
assuming your image name is green.png
05/19/2010 (6:07 am)
1) the bitmap should be a solid color2) the size does not have to be full size, it could be size 2x2. it gets resized / stretched from the code.
3) proper coding for bitmap should be ...
bitmap = "~/data/images/green";
assuming your image name is green.png
#6
05/19/2010 (4:58 pm)
I figured out why it wasn't appearing on screen. I needed to add the GuiControl to the mainScreen.gui file.
Torque Owner Scott Wilson-Billing
MeYuMe