Input Handling Questions
by Chris McKinney · in iTorque 2D · 08/25/2011 (8:53 pm) · 3 replies
Hi all,
I'm brand new to Torque and I have some confusion around input handling in iTorque. I have a few sprites tossed down and different places in my level. I'm trying to build some simple functionality that will allow me to drag the camera around the scene to look at different objects that are off-camera. Think Google Maps style drag functionality. To complicate matters somewhat, I'm doing my development on a Windows machine.
After reading the input tutorial, it seems that I can get close to my desired behavior using:
This moves my camera when I click in a given location. Ideally, I want the movement to be fluid. While mouse or finger is down, the camera should be moving with the input. This caused me to take a look at onMouseDragged(). This seems to give me really random results. I get huge world coordinates back (-10,000, 5000). Not sure why.
So getting to the root of my question:
I was hoping you guys could give me some guidance on the best way to accomplish my end goal. Any resources you could point me to would be great. Thanks!
I'm brand new to Torque and I have some confusion around input handling in iTorque. I have a few sprites tossed down and different places in my level. I'm trying to build some simple functionality that will allow me to drag the camera around the scene to look at different objects that are off-camera. Think Google Maps style drag functionality. To complicate matters somewhat, I'm doing my development on a Windows machine.
After reading the input tutorial, it seems that I can get close to my desired behavior using:
function t2dSceneWindow::onMouseDown(%this, %modifier, %worldPos) {
echo("onMouseDown event...");
sceneWindow2D.setCurrentCameraPosition(%worldPos);
}This moves my camera when I click in a given location. Ideally, I want the movement to be fluid. While mouse or finger is down, the camera should be moving with the input. This caused me to take a look at onMouseDragged(). This seems to give me really random results. I get huge world coordinates back (-10,000, 5000). Not sure why.
So getting to the root of my question:
- It is my understanding that onMouseDragged() isn't available on the device.
- I couldn't figure out a way to get the oniPhoneTouchMove() event to fire when using the mouse as the input device.
- Ideally, I would like my input handlers to be the same if I'm using a mouse for input vs touch. I realize this falls apart when we start thinking about multi-touch.
I was hoping you guys could give me some guidance on the best way to accomplish my end goal. Any resources you could point me to would be great. Thanks!
#2
Thanks for replying. I am using 1.4.1. Multi-touch is enabled on the project settings. Thanks for your guidance there.
I think this is probably just a case of me being silly and approaching this with the wrong mindset. As a test, I created a simple project on my Mac, put some code in the oniPhoneTouchMove callback, built the project with Xcode and tested it on the iOS simulator. This works as you would expect. The callbacks are called when I'm clicking around in the iOS simulator.
Really what I'm looking to have is this same functionality when I click the 'Play' button in the editor. Is there a way I can trigger the iPhoneTouch callbacks using mouse input? I develop on Windows, so I'm trying to avoid saving my project, pushing to the mac, building, and testing on the iOS simulator when I make a change. One possible alternative I see is that I could just use both the iPhoneTouch callbacks and the onMouse one. I'm just wondering if there's an option someplace to make everything use the same input callbacks.
Thank you for your assistance. I really appreciate it.
08/26/2011 (6:46 pm)
Hey Michael,Thanks for replying. I am using 1.4.1. Multi-touch is enabled on the project settings. Thanks for your guidance there.
I think this is probably just a case of me being silly and approaching this with the wrong mindset. As a test, I created a simple project on my Mac, put some code in the oniPhoneTouchMove callback, built the project with Xcode and tested it on the iOS simulator. This works as you would expect. The callbacks are called when I'm clicking around in the iOS simulator.
Really what I'm looking to have is this same functionality when I click the 'Play' button in the editor. Is there a way I can trigger the iPhoneTouch callbacks using mouse input? I develop on Windows, so I'm trying to avoid saving my project, pushing to the mac, building, and testing on the iOS simulator when I make a change. One possible alternative I see is that I could just use both the iPhoneTouch callbacks and the onMouse one. I'm just wondering if there's an option someplace to make everything use the same input callbacks.
Thank you for your assistance. I really appreciate it.
#3
I believe 1.5 will make this process a lot easier. You can read my coverage of the new input system in this thread. I don't know if you can wait or work on other parts of the game until the final 1.5 is released, but it is an option that is not far off.
A simple example of pseudo code that will make this easier in 1.5 is this:
You can share 90% of the code between the two functions, making testing on Windows and device much easier.
08/27/2011 (8:05 am)
@Chris - Ah, I see now. So the oniPhoneTouch commands do not work on Windows or OS X. They will only trigger on the simulator or device. If you wanted them to, you would need to modify the engine source to fire off differently depending on the platform.I believe 1.5 will make this process a lot easier. You can read my coverage of the new input system in this thread. I don't know if you can wait or work on other parts of the game until the final 1.5 is released, but it is an option that is not far off.
A simple example of pseudo code that will make this easier in 1.5 is this:
if($platform $= "iPhone")
{
moveMap.bind(touchdevice, touchdown, "touchesDown");
}
else
{
moveMap.bind(mouse, button0, "touchesDown");
}You can share 90% of the code between the two functions, making testing on Windows and device much easier.
Employee Michael Perry
ZombieShortbus