Using touch/mouse callbacks on individual sprites
by Joe Williams · in Torque 2D Beginner · 03/30/2013 (12:11 am) · 2 replies
This code used to work in old TorqueScript (except it was setUseMouseEvents instead of setUseInputEvents). What is the proper procedure for having individual sprites (as part of their class functions) respond to touch? The existing toys don't seem to do any of the interface this way.
With that code, the blocks are created and their collision polygons are set. I can verify this by running my player character into them and pushing them around. They don't respond to touch/mouse at all, though. Any ideas on getting the "buildingBlock" to respond to touch/mouse so it can be dragged and dropped?
function CFD::createBlock( %this, %size, %type )
{
%obj = new Sprite() { class = "buildingBlock"; };
%obj.setImage( "CFD:panel" @ %size );
%obj.setSize( 1, %size * 2 );
%obj.setDefaultDensity( %size );
%obj.createPolygonCollisionShape( "0.5 0 0.5 -" @ %size @ " -0.5 -" @ %size @ " -0.5 0" );
%obj.setUseInputEvents( true );
%obj.attached = false;
%obj.closePoint = false;
%obj.setPosition( %size * 2, 3 );
%obj.LinearDamping = 3;
%obj.AngularDamping = 5;
SandboxScene.add( %obj );
return %obj;
}
function buildingBlock::onTouchDown( %this, %touchID, %worldPosition )
{
echo( "TouchDown" );
%this.setMouseLock( true );
if( !%this.attached )
{
%this.setPosition( %worldPosition );
}
}
function buildingBlock::onTouchDragged( %this, %touchID, %worldPosition )
{
%this.setPosition( %worldPosition );
}
function buildingBlock::onTouchUp( %this, %touchID, %worldPosition )
{
echo( "TouchUp" );
%this.setMouseLock( false );
}With that code, the blocks are created and their collision polygons are set. I can verify this by running my player character into them and pushing them around. They don't respond to touch/mouse at all, though. Any ideas on getting the "buildingBlock" to respond to touch/mouse so it can be dragged and dropped?
About the author
Recent Threads
#2
03/30/2013 (5:19 am)
Also, check out some recent changes to the input system by reading my latest blog.
Torque Owner Joe Williams
Newborn Games