Mouse events per class
by Pedro Vicente · in Torque 2D Beginner · 10/28/2013 (1:13 pm) · 1 replies
I am porting a iTorque 1.5 project to Torque 2D
I have this code that creates a "button", which is a sprite that responds to mouse events
If I call this function with
It creates a sprite "connected" to the class named "MainMenuButtonRun"
So, I can define
and when the button is clicked with the mouse this function is called.
When trying to do the same in Torque 2D
the mouse event is not triggered
I have this code that creates a "button", which is a sprite that responds to mouse events
iTorque 1.5 code
function CreateButton( %scenegraph_obj, %class, %image_map, %xpos, %ypos, %xsize, %ysize )
{
%obj = new t2dStaticSprite()
{
scenegraph = %scenegraph_obj;
class = %class;
useMouseEvents = "1";
};
%obj.setVisible( true );
%obj.setImageMap( %image_map );
%obj.setPosition( %xpos, %ypos );
%obj.setSize( %xsize, %ysize );
%obj.setLayer( 1 );
return %obj;
}If I call this function with
CreateButton( %this, "MainMenuButtonRun", "ButtonStartImageMap", 0, 0, 128, 128);
It creates a sprite "connected" to the class named "MainMenuButtonRun"
So, I can define
function MainMenuButtonRun::onTouchUp( %this, %modifier, %worldPosition, %clicks )
{
} and when the button is clicked with the mouse this function is called.
Torque 2D code
When trying to do the same in Torque 2D
function CreateButton(%class, %image_map, %xpos, %ypos, %xsize, %ysize )
{
%obj = new Sprite()
{
class = %class;
useMouseEvents = "1";
};
%obj.setVisible( true );
%obj.setImage( %image_map );
%obj.setPosition( %xpos, %ypos );
%obj.setSize( %xsize, %ysize );
%obj.setSceneLayer( 1 );
CaScene.add( %obj );
return %obj;
}the mouse event is not triggered
Associate Mike Lilligreen
Retired T2Der
And at the SceneObject level, the field is no longer called UseMouseEvents but rather UseInputEvents.