Not logged inGosu Forums
Forum Gosu Homepage Help Search Register Login
Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Input on iOS
- - By jlnr (dev) Date 2010-06-18 07:13 Edited 2010-07-16 17:08
The current model for input is now like this:

Gosu::Input::currentTouches returns a vector of the touches currently on the surface.

Gosu::Window::touchBegan/touchMoved/touchEnded(Gosu::Touch touch) are the callback functions where you can handle touches. They are like buttonDown and buttonUp, except they don't take a Gosu::Button but a Gosu::Touch.

Gosu::Touch contains coordinates and a "void* id" flag. This is used to identify touches while they last, i.e. the same finger will get the same "id" until it is released. Use this to remember which touch started when and where if you need it.

For example, a use case might be writing a button. The button has a boost::optional<Gosu::Touch> member variable.
• In touchBegan, if there is no current touch, you check if the touch is over the button. If so, the button remembers it by copying the Gosu::Touch into the member.
• In touchMoved, you check if the id of the touch is the same as the remembered one. If so, you update the stored Touch.
• In touchEnded, you compare the id against that of the remembered touch. If it is the same, you clear out the member variable. If the touch was close enough to the button when releasing, you trigger an event.
• In the button's rendering code, you can check if there is a touch and it is still close enough to determine whether the button should be drawn pressed down.

Gosu::Input::setMouseFactors (actually undocumented) sets two factors that will also be applied to all touches. You can use this, and the similarly undocumented Gosu::Graphics::setResolution to virtually scale and existing game down to iPhone size. They both might be replaced by matrices soon, though.
Parent - By jlnr (dev) Date 2010-06-18 07:14 Edited 2010-06-18 07:40
Note that touchBegan only takes a single touch (Touch touch) now. A couple commits ago it took a vector of touches (const Touches& touches).

THIS SILENTLY BREAKS CODE. Your touchesBegan function in Window is not going to be called anymore. Blame C++ for not having an "override" keyword that complains when the base class removes a virtual function. :|
Parent - - By Basic Date 2010-06-18 08:51
ah this makes a lot more sense to me. My iPad arrives sometime today so I can give this a shot tonight or on the weekend.
Parent - By jlnr (dev) Date 2010-06-18 14:51
Grats :) If your game needs to differentiate between iPhone, iPad and iPhone4, you can already use Gosu::screenWidth() and Gosu::screenHeight() which should work as expected.
Parent - - By Basic Date 2010-06-20 06:10
I'll get there in the end with this.

calling windowInstance().input().currentTouches(); brings back the error "class Gosu::Input has no member named 'currentTouches'

am I calling this wrong?
Parent - - By Basic Date 2010-06-20 07:54
I got it I had not updated the Gosu.framework, so the headers where all wrong.

however in doing so I got another error complaining about Gosu/Version.hpp not existing called from Gosu.hpp. I just commented the line out and it all works fine now.
Parent - By jlnr (dev) Date 2010-06-20 10:44
Oops—I updated the Xcode project so that Version.hpp should now be included if anyone should ever need it for any weird compatibility workarounds. :)
Parent - - By jlnr (dev) Date 2010-07-16 15:01
Dear huge Gosu Touch userbase :D,

Any objections towards kicking out the touchMoved event? I really don't see the point. You might as well just poll in a Gosu-based application.
Parent - - By Basic Date 2010-07-16 15:51
erm, well I dont mind :D
Parent - - By jlnr (dev) Date 2010-07-16 16:51 Edited 2010-07-16 17:08
Never mind. I actually realized I had an elegant way to use it somewhere in my codebase. Documented how I do buttons as an example—I actually like the touchMoved method for that.
Parent - By Basic Date 2010-07-16 18:49
ok, we like that method now :D
Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Input on iOS

Powered by mwForum 2.29.1 © 1999-2013 Markus Wichitill