onBehavior Add & Remove Defaults
by rennie moffat · in Torque Game Builder · 09/21/2009 (5:16 pm) · 2 replies
I am just wondering, if you notice these on add and remove behaviors, both declare up, down, left right as = 0. I would expect on remove to be one or vice versa. Why are the the same, and for that matter I suppose, what is the purpose of this default? Is it to simply to reset if error?
function MovementBehavior::onBehaviorAdd(%this)
{
if (!isObject(moveMap))
return;
// bind our keys to the keyboard
moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "moveUp", %this);
moveMap.bindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), "moveDown", %this);
moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveLeft", %this);
moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "moveRight", %this);
// set the default values to 0
%this.up = 0;
%this.down = 0;
%this.left = 0;
%this.right = 0;
}
function MovementBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
// remove the keybinds
moveMap.unbindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), %this);
moveMap.unbindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), %this);
moveMap.unbindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), %this);
moveMap.unbindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), %this);
%this.up = 0;
%this.down = 0;
%this.left = 0;
%this.right = 0;
} About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
Associate William Lee Sims
Machine Code Games