Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2011, 02:20 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 9
dilideskon is on a distinguished road
Default When are the touch events called?

- (void) loop
{
[self update];
[self render];
}

That is my main loop for my game.
It's part of a game state and each state has that loop which will be then called by the view controller.
The state inherits UIView, which means it has all the methods regarding touch events.

I was wondering when these methods such as touchesEnded and touchesBegan are evoked.
dilideskon is offline   Reply With Quote
Old 02-12-2011, 04:38 PM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

The main thread of any iPhone app has something called a RunLoop that is managing a queue of events. If your loop is run of an NSTimer, which is common, the timer event is one of the things placed in the queue. Touch events are also placed in the queue, and called whenever they move to the top of the queue.

So after 1 frame of your loop is called, the RunLoop calls any touch or other events that have happened while your loop was running. Then, when all those are done, the next frame of your loop is called, and so on.

Is that what you were looking for?
JasonR is offline   Reply With Quote
Old 02-12-2011, 04:51 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 9
dilideskon is on a distinguished road
Default

Quote:
Originally Posted by JasonR View Post
The main thread of any iPhone app has something called a RunLoop that is managing a queue of events. If your loop is run of an NSTimer, which is common, the timer event is one of the things placed in the queue. Touch events are also placed in the queue, and called whenever they move to the top of the queue.

So after 1 frame of your loop is called, the RunLoop calls any touch or other events that have happened while your loop was running. Then, when all those are done, the next frame of your loop is called, and so on.

Is that what you were looking for?
Yes. Thank you.

I use displayLink like below:
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
[displayLink setFrameInterval:nil];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

So when an event occurs, it adds to the main application loop which then late called when "one frame" is moved right?

I'd like to visualize my understand. Please correct me if I'm wrong:

RunLoop (Main App) = what happens in ONE FRAME
{
events (including touch) -> allSortOfPotentialThingsImNotAwareOf -> displayLink -> repeat
}
dilideskon is offline   Reply With Quote
Old 02-13-2011, 05:53 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

That matches my understanding. There's also secret stuff happening on other threads, especially if you are using any network calls, but that does not change anything for your game loop.
JasonR is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 422
9 members and 413 guests
7twenty7, chemistry, ChrisYates, hussain1982, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0