Game Development Community

Is there a good way make on screen touch controls?

by Alexander Fyrdahl · in iTorque 2D · 01/01/2012 (3:28 pm) · 2 replies

Hey all! I apologize if you're all sick and tired of hearing about this but I'm new to iTorque (1.5). Been playing around a bit, reading tutorials etc and right I'm trying it make a good touch control. Nothing fancy, just a button for left, right and jump. I've been looking into Ray Delia's awesome (thank you Ray!) tutorial "iPlatformer" and his method worked very well until i added camera movement and realized my player was running away from the buttons ;). What I discovered as the buttons went off screen was that onTouchUp only works if you release the touch on top of the button. With stationary buttons that is not that apparent, but it can be very annoying and a fix is needed.

Keeping the buttons stationary was easily fixed by adding a new scene with my buttons and overlaying it over my level. For some reason I had to use pushDialog for it to show up correctly on the iPhone while it worked without it in iTGB but it all worked out.

I'm not having much luck with the onTouchUp though, been reading a lot around the forums but I can't seem to figure out if anyone solved the issue. Someone was mentioning a change he made in the engine source without further explanation.

Having so much fun tweaking and experimenting, it would be a bummer if I couldn't solve this problem.

#1
01/02/2012 (9:20 pm)
If you take a look at the second post in this thread
www.garagegames.com/community/forums/viewthread/127943
I provide a solution for touch controls that aren't object based, but are scene based. This way you can accurately handle a single touch which corresponds to multiple objects. In your case if you only want to respond to touches on control 'buttons' in the controls scenegraph it should actually be quite simple.
#2
01/20/2012 (12:42 pm)
You could also try to lock the mouse to the object with

%object.setMouseLocked(true);

This should let the onTouchUp callback be fired for the object even if the touch event occurs off the object. You can lock the mouse in onTouchDown and then release it in onTouchUp.

I've found this functionality very useful when adding drag functionality to an object. If you are adjusting the object's position in the onTouchDragged method and you drag too quickly, the touch event will register off the object and it will get left behind. Using setMouseLocked when dragging fixes this.