can an object allow for another object to use mouseEvents?
by rennie moffat · in Torque Game Builder · 03/10/2010 (11:05 am) · 4 replies
is something like this possible? as in if i have a behavior with 4 objects as behaviorFields. if the player position Y is equivalnet to the owner pos Y, then the owner, sets the 3 objects to setUseMouseEvents(true). So essentially I am trying to get the owner to allow for other objects to use mouse events.
if(!isObject(h1bar))
{
%template = new behaviorTemplate(h1bar);
%template.friendlyName = "h1 bar";
%template.description = "manages h1 boxes";
%template.behaviorType = "hvBar";
%template.addBehaviorField(h1Box1, "", object, "", t2dSceneObject);
%template.addBehaviorField(h1Box2, "", object, "", t2dSceneObject);
%template.addBehaviorField(h1Box3, "", object, "", t2dSceneObject);
%template.addBehaviorField(mouser, "", object, "", t2dSceneObject);
%template.addBehaviorField(velocity, "", float, "");
}
function h1bar::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
$h1box1PosX = getWord(%this.h1Box1.getPosition(), 0);
$h1box1PosY = getWord(%this.h1Box1.getPosition(), 1);
$h1box2PosX = getWord(%this.h1Box2.getPosition(), 0);
$h1box2PosY = getWord(%this.h1Box2.getPosition(), 1);
$h1box3PosX = getWord(%this.h1Box3.getPosition(), 0);
$h1box3PosY = getWord(%this.h1Box3.getPosition(), 1);
}
function h1bar::onUpdate(%this)
{
$h1barPosY = (getWord(%this.owner.getPosition(), 1));
if($h1barPosY == $playerPositionY)
{
%this.h1Box1.setUseMouseEvents(true);
%this.h1Box2.setUseMouseEvents(true);
%this.h1Box3.setUseMouseEvents(true);
}
}
function h1bar::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
if(isObject(%this.h1Box1))
%this.mouser.moveTo($h1box1PosX, $h1box1PosY, %this.velocity, true);
if(isObject(%this.h1Box2))
%this.mouser.moveTo($h1box2PosX, $h1box2PosY, %this.velocity, true);
if(isObject(%this.h1Box3))
%this.mouser.moveTo($h1box3PosX, $h1box3PosY, %this.velocity, true);
}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.
#2
the only reason why i am not too concerned about using position as the conditions is because I am lining up all my tiles (objects which onMouseUp(if active) call the player to move one to it, at its 0, 0 mark) and thus, the player will be inline with all axis.
This works I have done it, the reason why i want to use a separate object to dictate if that WHOLE LINE of boxes are active. If a wall separates a line of boxes, then the one side of the wall where the player is on will will be active, on the other side the where the player is not, tho being on the same axis will not work.
Collisions do not work here because they take the player off of his axis.
At worst a range could work here but I would rather stay exact.
03/10/2010 (12:44 pm)
rounding up and rounding down is something that does interest me. the only reason why i am not too concerned about using position as the conditions is because I am lining up all my tiles (objects which onMouseUp(if active) call the player to move one to it, at its 0, 0 mark) and thus, the player will be inline with all axis.
This works I have done it, the reason why i want to use a separate object to dictate if that WHOLE LINE of boxes are active. If a wall separates a line of boxes, then the one side of the wall where the player is on will will be active, on the other side the where the player is not, tho being on the same axis will not work.
Collisions do not work here because they take the player off of his axis.
At worst a range could work here but I would rather stay exact.
#3
03/10/2010 (3:58 pm)
While I've not tested your code, the concept will work. Make sure that you turn off mouse events when the player isn't aligned.
#4
03/10/2010 (4:13 pm)
yes, ok, perhaps i have to play with it more. maybe something is just off, but i am glad i have confirmation the idea is solid.
Associate Mike Lilligreen
Retired T2Der