Game Development Community

REceiving mouse/touch events in native behavior

by Bret Patterson · in iTorque 2D · 05/14/2009 (7:08 am) · 8 replies

How can I receive touch and mouse events in a native behavior?

I figured I can receive mouse events by creating a console function but that doesn't seem to work
for touch events.

#1
05/14/2009 (9:28 am)
Using the resource I posted last night (at http://www.garagegames.com/community/resources/view/17225), touch events are passed through the same mouse events as everything else. So your objects will be able to receive individual touch events that respond to the existing 'onMouseDown', 'onMouseMove' and other 'onMouse' callbacks.

If you want these to be more-native and not use the existing onMouse callbacks, you will need to create some new callback types. Search through the code for 'onMouseDown' and follow the code path through to here in guiCanvas.cc:

void GuiCanvas::rootScreenTouchDown(const GuiEvent &event)
{
	mPrevMouseTime = Platform::getVirtualMilliseconds();
	mMouseButtonDown = true;

		iterator i;
		i = end();
		while (i != begin())
		{
			i--;
			GuiControl *ctrl = static_cast<GuiControl *>(*i);
			GuiControl *controlHit = ctrl->findHitControl(event.mousePoint);
			
			//see if the controlHit is a modeless dialog...
			if ((! controlHit->mActive) && (! controlHit->mProfile->mModal))
				continue;
			else
			{
				controlHit->onMouseDown(event);
				break;
			}
		}
	
	if (bool(mMouseControl))
		mMouseControlClicked = true;
}

See the part that reads "controlHit->onMouseDown(event);"? That's where we are sending the actual callback to the single object. At that point you could send another callback instead, such as "controlHit->onTouchOccured(event);". It's also there where you could track 2 positions on the screen at once to see if the user is pinching the screen.
#2
05/15/2009 (9:49 am)
Thanks I'll look into it when I get time. This stuff isn't high priority for me right now and it seems complicated because I use behaviors for everything. I couldn't get oniPhoneTouch events to be sent to behaviors console methods directly on a first pass.

I have plans for pinch zoom and other gesture additions to my game, but not until an add-on when I add new classes that people can play.
#3
05/15/2009 (9:54 am)
Yea, the oniphonetouch events didn't seem too useful to me, either. I initially wrote a script-level wrapper that utilized them, and it actually did (mostly) work, but it was real slow (hacked the framerate straight down).

New chassis? Sounds like you've got a fun mech game going on over there. :)
#4
05/15/2009 (10:29 am)
classes, action RPG :). Though an action Mech RPG sounds like a good idea..
#5
05/15/2009 (10:34 am)
You know, you typed 'classes', but the font on my screen makes it look like 'chasses', so I got 'chassis' out of that, lol.

Action RPG still sounds cool, though!
#6
05/15/2009 (11:23 am)
Leans more towards a hard core RPG but trying to make it as much action as I can, though it's going to have the "grind" session feeling of most hardcore RPG's.

Still have a ton left to do, UI layer, Items, Load/Save, Level Transitions, Multi-player (this should be interesting), and scripted encounters.

Big thing I'm worried about is artwork, I've sent off an asset list to an outsourcing agency and we'll see about timeframe/cost. This is my first game so I have no idea about art costs nor the time it takes to do them. It's a little ambitious for a solo operation, but then again it's the game I'd want to play which makes it more fun/interesting.
#7
05/15/2009 (11:25 am)
If their price is nasty, we can talk. I've got some pretty good artists on my team over here at Gaslight Studios... I'm sure we could work out a price that fits your budget.
#8
05/15/2009 (11:38 am)
Thanks I appreciate the offer. I'll definitely take you up on it if the other place doesn't work out. I'm hoping to start a solid relationship with a company for artwork for future games also, until I can transition into hiring my own local staff or taking on partners. Should be about another year, maybe two at most if things go well.