Game Development Community

Mouse interface not working- (Solved)

by Jeremy Dull · in iTorque 2D · 05/04/2012 (7:46 am) · 2 replies

I have just recently started working with iTorque 1.5 where I was previously using 1.4. I have restarted my project from scratch as I had a lot of junk code in my 1.4 version. I tried to copy over some of my code into the 1.5 version and I am not getting the results that I would have expected. Namely the mouse controls. In my 1.4 version I was coding everything with mouse control so that I was able to test to ensure functionality of the game. Now I can't seem to do that am I missing something? Here is my problem:

I like the multi touch support and have looked at the whole actionMap aspect of the game. I have a actionMap(gameMap) that I replaced the moveMap with for all of my touch based controls. I haven't tested this yet on the iPad itself. I have been just trying to get the game to work on the PC where I do all my programming from first. Here is what I have for the mouse binding code which is what was working in the 1.4 version.

moveMap.bindCmd(mouse, "button0", "onMouseDown();", "onMouseUp();");

function sceneWindow2D::onMouseDown(%this,%mod,%worldPos,%mouseClicks)
{
if($debugMsg::mouse::callBacks)
echo("Mouse Down");

//Set the bridge starting point
//echo(%worldPos);
$bridgeStartPoint = %worldPos;
}

I didn't get the mouse to work with the old code I have since tried making a new actionMap and making sure that I am in fact pushing the actionMap in the startGame code. The latest I have is:

new ActionMap(mouseMap);
mouseMap.bindCmd(mouse, "button0", "onMouseDown();", "onMouseUp();");

function sceneWindow2D::onMouseDown(%this,%mod,%worldPos,%mouseClicks)
{
//if($debugMsg::mouse::callBacks)
echo("Mouse Down");

//Set the bridge starting point
//echo(%worldPos);
$bridgeStartPointX = getWord(%worldPos, 0);
$bridgeStartPointY = getWord(%worldPos, 1);
}

I have looked through the documentation and found the info on the mouse to be used for a specific object using the behavior onTouchDrag movement thing. I have that working fine if I use that on an object. My problem is that the code is supposed to let the player click/touch a place on the screen and then drag and release to create an object in game. I checked the scenegraph in the gui and both useWindowMouseEvents = "1"; useObjectMouseEvents = "1"; are showing that they are true and I am stuck.

Any help that can be given would be appreciated. I really don't want to have to port my game over to test every little change as it kind of defeats the purpose of scripting.

About the author

Founder and CEO of Blackstaff Studios. Our focus is to make fun and simple games and software for the everyday person. Currently working on a project for the iOS platform using iTorque 2D


#1
05/06/2012 (9:59 am)
Have you tried setting the scene window to respond to the onTouch... functions? Something like this?

function sceneWindow2D::onTouchDown(%this,%touchID, %worldPos){
//if($debugMsg::mouse::callBacks)
echo("Mouse Down");

//Set the bridge starting point
//echo(%worldPos);
$bridgeStartPointX = getWord(%worldPos, 0);
$bridgeStartPointY = getWord(%worldPos, 1);
}

By the way, you can do something like %worldPos.X and %worldPos.Y to get the X and Y coords from that parameter, in case you don't want to keep using getWord (which I think is less efficient).

Edit: Rewritten to actually answer your question.
#2
05/06/2012 (4:40 pm)
Joe,

Thank you so much I have been raking my brain on this one for a week. It is working perfectly with that code sample you gave. I really appreciate the help.

It is kind of weird though since it seems this code is independant from the actionMaps since I don't seem to need them and the code is still called. I assume it is somewhere in the engine itself that is giving it this functionality.

Again Many thanks, now I just need to go and tweak the function to get the proper output which will be a snap now that my mouse clicks are actually doing something.