Game Development Community

new to iTGB .. mouse input probem [solved]

by Rami Bokhari · in iTorque 2D · 06/11/2011 (2:22 pm) · 7 replies

hey guys.. I wanted to port my game to the iphone. basically I'm using a behavior to rotate an object toward the mouse.. it's not working on the iphone

can I use onMouseMove on the iphone? or I should use onTouchMove?

here is the behavior I'm using:

//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

if (!isObject(FaceMouseBehavior))
{
   %template = new BehaviorTemplate(FaceMouseBehavior);
   
   %template.friendlyName = "Face Mouse";
   %template.behaviorType = "Mouse Input";
   %template.description  = "Set the object to always face the mouse";
   
   %template.addBehaviorField(turnSpeed, "The speed to rotate at (degrees per second). Use 0 to snap", float, 0.0);
   %template.addBehaviorField(rotationOffset, "The rotation offset (degrees)", float, 0.0);
}

function FaceMouseBehavior::onBehaviorAdd(%this)
{
   %this.owner.setUseMouseEvents(true);
}

function FaceMouseBehavior::onAddToScene(%this, %scenegraph)
{
   %this.owner.setMouseLocked(true);
}

function FaceMouseBehavior::onMouseMove(%this, %modifier, %worldPos)
{
   %vector = t2dVectorSub(%worldPos, %this.owner.position);
   %targetRotation = mRadToDeg(mAtan(%vector.y, %vector.x)) + %this.rotationOffset;
   
   if (%this.turnSpeed == 0)
      %this.owner.setRotation(%targetRotation);
   else
      %this.owner.rotateTo(%targetRotation, %this.turnSpeed, true, false, true, 0.1);
}

function FaceMouseBehavior::onMouseDragged(%this, %modifier, %worldPos)
{
   %this.onMouseMove(%modifier, %worldPos);
}



basically I want to rotate an object toward the finger

About the author

I love video games.. video games are my life.. playing can't satisfy me anymore.. thank you GG helping me making my dream worlds a reality


#1
06/11/2011 (4:00 pm)
info: when I test the game on iTGB for windows.. the rotation works fine!
only in the iphone it doesn't work.. I don't know I heard iTGB sees mouses like touches...
#2
06/11/2011 (5:07 pm)
it does. but in porting to the iPhone iTGB must set any object which moves in anyway, including rotation, must have itself (the object) set usesPhysics = "1"; in it's datablock. You can do this by simply checking it off as true in the object's physic's panel. This I suspect is your issue.


#3
06/12/2011 (3:04 am)
thanx man.. I checked the 'use physics' box.. but still not working on the iphone
#4
06/12/2011 (8:49 am)
Not sure. The code if it works in iTGB should work in the and on the iPhone. Does it work in the simulator (iPhone)?
#5
06/12/2011 (9:30 am)
no it's not working in the simulator.. but it works fine on the level builder.. and in the windows version of the game
#6
06/12/2011 (10:15 am)
I just changed onMouseMove to onMouseDown

no it's working.. thanx rennie :)
#7
06/12/2011 (10:34 am)
good.