![]() |
|
Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Advice on coding of On-Screen Controls ( Joystick and multiple buttons) (/thread-878.html) |
Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Elphaba - Aug 9, 2009 07:30 AM Hi I'm finally getting somewhere now! ![]() I'd just like to know if there are any good tutorials or advice or even code snippets on how best to handle on screen controls and multiple buttons presses / releases. The way I've implemented it, is that I've abstracted out of the EAGLView the touch events and they are being passed down a chain to an object that is just concerned with making 'sense' of them. I have the requirement for a joystick (say, D-Pad) on the left of the screen and three buttons on the right. The three buttons can be pressed down at the same time as one or more of the D-Pad buttons, however, no more than one of the buttons on the right can be down at the same time. Also, no more that 2 of the D-Pad buttons can be down at the same time, and as ofcourse, with a D-Pad I must expect the user to drag/move their finger from one part of the buttons to another and transition accurately between these 'states' At the moment I've got the 'touchesBegan:touches blah blah' event passing the entire NSSet * of touches down to my delegate, so I can get the 'full' list of touch events. But how do I seperate them out and make sense of it all? My first attempt, was just to get the current position of the touch and make a basic ( if touch.x > button1.x and touch.x < button1.x + button1.width) blah blah blah for all the buttons, but I scrapped that because it can't handle all the 'semantics' of what I need. Can anyone please advise? Thanks so much. Elphaba Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Elphaba - Aug 10, 2009 11:16 AM *bump* Anyone? Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - ThemsAllTook - Aug 10, 2009 11:53 AM I'd approach it like this:
Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Elphaba - Aug 10, 2009 07:15 PM Sorry Thems... That doesn't help. Knowing if the touch happened in an area is not the problem. The problem is with the standard event handlers as I mentioned and handling the 'multi touch ' and a touch MOVED / END on the D-PAD at the same time another touch Down/Up is happening on a button. THAT'S the hard part -and one I can't find any help on. Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Bachus - Aug 10, 2009 07:46 PM Something like this? Code: - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)eventtouchesMoved:withEvent: is basically the same and touchesEnded:withEvent is the same, but in reverse (buttons deactivating, etc). You can test against the touch's previous location with... Code: CGPoint oldLocation = [touch previousLocationInView:self];... to see if a touch has left a button's rect without being released. Advice on coding of On-Screen Controls ( Joystick and multiple buttons) - Elphaba - Aug 10, 2009 11:02 PM Bachus Wrote:Something like this? Yeah, kinda. Thanks Bachus. That's kinda what I've already got, except I'm using the ' Code: for ( UITouch * touch in touches)The problem I'm having - and have had all this time is with the 'touchesMoved' method. Example: If I move my finger over the D-Pad, I want to track the movement and operate upto 2 adjacent sectors, i.e. Left and Up.. okay? BUT if I move my finger from say the 'up' position, and move it OFF of the on-screen D-Pad, then I need to 'release' the D-Pad. Same goes for the 3 buttons on the right hand side. If I press them, and then move / drag my finger up and off of them, but still in contact with the screen, they 'stay pressed' and not released. This is my big mental block. Thanks |