Dynamic Generic Button Behavior
by R. Carpenter · in Torque Game Builder · 12/15/2009 (7:23 pm) · 1 replies
Hello all,
Iv'e been messing around with the " Generic Button Behavior" found in the behavior section. Using the Shooter tutorial as a base, I added the Generic Button Behavior to the enemy ships so that when I click on the enemy ships a static sprite is created and mounted over the enemy. My problem is that I'm having trouble adding the generic button behavior to the static sprite (i'd like to click on the sprite and have the enemy blow up)
here is the code iv'e bee workign with...
Iv'e been messing around with the " Generic Button Behavior" found in the behavior section. Using the Shooter tutorial as a base, I added the Generic Button Behavior to the enemy ships so that when I click on the enemy ships a static sprite is created and mounted over the enemy. My problem is that I'm having trouble adding the generic button behavior to the static sprite (i'd like to click on the sprite and have the enemy blow up)
here is the code iv'e bee workign with...
function enemyShip::createButton(%this)
{
%this.enemyButton = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
imageMap = "ButtonImageMap";
frame = "0";
size = "50.000 50.000";
};
%this.enemyButton.mount(%this, "-0.005 -1.513", 0, true, true, true, true);
%behavior = GenericButtonBehavior1.createInstance();
%this.enemyButton.addBehavior (%behavior);
%this.enemyButton.method = onClick1;
}
function enemyShip::onClick(%this)
{
%this.createButton();
}
function enemyShip::onClick1(%this)
{
%this.explode();
}About the author
Associate William Lee Sims
Machine Code Games
Also, I think you need to assign the method to the behavior, not to the object. (As in, "%behavior.method = onClick1;".)
If this doesn't work, just let me know and I'll take a second look.