LifeCounter
by William James · in Torque Game Builder · 02/11/2008 (7:13 am) · 4 replies
I was going through the asteroid tutorial and I noticed the takedamage behavior.
Im trying to get a different image to be displayed for each life count.(ie 3 lives left shows a ship completely filled, 2 lives= ship 2/3 filled, .....). I'm thinking of adding a new field to the behavior for a image to be loaded in the takedamage.cs and change the frame of the image as the lives change. Any suggestions..
Im trying to get a different image to be displayed for each life count.(ie 3 lives left shows a ship completely filled, 2 lives= ship 2/3 filled, .....). I'm thinking of adding a new field to the behavior for a image to be loaded in the takedamage.cs and change the frame of the image as the lives change. Any suggestions..
#2
1. I put the imagemap on the screen that I want to display the lives
2.I added this in the behavior
02/11/2008 (10:45 pm)
I can't seem to get it to work. 1. I put the imagemap on the screen that I want to display the lives
2.I added this in the behavior
%template.addBehaviorField(image, " This is the image used to display player lives", object, "", t2dImageMapDatablock);3. Then in the kill function I added setImageMap(%this.image, 3);
function TakesDamageBehavior::kill(%this)
{
if (%this.lives <= 0)
{
setImageMap(%this.image, 3);
%this.owner.safeDelete();
return;
}
%this.invincible = true;
%this.owner.visible = false;
%this.owner.collisionActiveReceive = false;
%this.schedule(%this.respawnTime * 1000, "spawn");
}
#3
First of all, if you are dragging an imageMap into your scene then it's probably a t2dStaticSprite. So change the behavior field to t2dStaticSprite or t2dSceneObject. Also, for it to show up in the TGB editor behavior field you need to give the sprite a name in the scripting rollout under the edit tab.
Then in the kill function you are only trying to change frame when the ship has no lives left. If this is what you intend, the function should be more like this:
02/12/2008 (11:50 am)
Few mistakes here.First of all, if you are dragging an imageMap into your scene then it's probably a t2dStaticSprite. So change the behavior field to t2dStaticSprite or t2dSceneObject. Also, for it to show up in the TGB editor behavior field you need to give the sprite a name in the scripting rollout under the edit tab.
Then in the kill function you are only trying to change frame when the ship has no lives left. If this is what you intend, the function should be more like this:
function TakesDamageBehavior::kill(%this)
{
if (%this.lives <= 0)
{
%this.image.setFrame(3);
%this.owner.safeDelete();
return;
}
%this.invincible = true;
%this.owner.visible = false;
%this.owner.collisionActiveReceive = false;
%this.schedule(%this.respawnTime * 1000, "spawn");
}
#4
THANKS. This worked. I just changed code a little to change for decrement of all lives.
02/15/2008 (9:01 am)
[RESOLVED]THANKS. This worked. I just changed code a little to change for decrement of all lives.
Associate Mike Lilligreen
Retired T2Der