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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-17-2010, 12:38 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 253
Default Need a better approach for a reaction style game

I have an idea for a reaction style game, the basic idea of which is that an image such as
a cherry or an apple displays for a short time and it is up to the player to tap a button or miss
tapping the button and losing a point of health.

The way I have done it is to have an array, in this case a switch-case juggle between methods...


How it works is, there is an variable at the start of the game that is set to 0. The button for each image is
made visible while the timer is running and the player is supposed to tap it. The IBAction for the button
simply changes the variable to "1" and the method checks for a 1 or a 0 to see if the button had been
pressed in the alloted time or not.




However, it runs really jerky and sporadic. Wondering if there is a better way of doing this.

Last edited by davejas69; 03-17-2010 at 12:41 PM.
davejas69 is offline   Reply With Quote
Old 03-18-2010, 11:22 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

You need to figure out what your choke point is -- loading the images, or setting the .image property -- and start doing that up front when your game loads.

Loading the images earlier and setting gameImage.image = [imageArray objectAtIndex: n] may speed things up, or you may have to create multiple UIImagViews and show/hide them instead of changing the .image property.

On the style side, if rNumber was an instance variable then you could have a single fruitMethod instead of three different methods, and cut down on duplicate code. Also, you have multiple timers and you're not saving pointers to any of them, so you'll have trouble canceling them if you ever need to dealloc this view. Finally, creating a series of non-repeating timers will not be as smooth as a single repeating timer calling a gameUpdate method.

Hope this helps.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 03-18-2010, 01:16 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 253
Default

This does help. I think that calling the non repeating timers was causing
the jerkiness. I haven't rewritten this completely yet but am I on the
right track?


davejas69 is offline   Reply With Quote
Old 03-18-2010, 02:04 PM   #4 (permalink)
Registered Member
 
mobileben's Avatar
 
Join Date: Jul 2009
Location: Zgrunturos
Posts: 161
Default

What you really want to do is use a one main timer that feeds the rest of your game approach. Something where you set up your base timer once with something like:

timerBasedLoopTimer = [NSTimer scheduledTimerWithTimeInterval:1.0F / 60.0F target:self selector:@selector(timerBasedLoop) userInfo:nil repeats:YES];

And then your timerBasedLoop (in the example above), calls your game loop. That game loop should then call everyone else. Your best bet is to have that base game loop keep track of the time. It can also decide if things need stuff at a different rate (eg. refresh every 1 sec versus every 1/30th of a sec).

The real trick, which most beginners and frankly even some "pros" don't want to do is use frame independent code. This means using time to do everything rather than the number of frames that have occurred.
__________________
Have a Poketastic time with QuitIt!
Arcade Basketball at it's best! Hoops Madness!
VS action on the iPad with Hoops Madness VS!
Sweet trailer here!
mobileben 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: 265
19 members and 246 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, JasonR, mer10, prchn4christ, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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