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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-25-2011, 12:39 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 35
Kenenth is on a distinguished road
Default How can I make Objects fall down the screen in waves?

In my app, there are objects that are getting pulled down the screen by an nsTimer that fires every 1/60 of a second and pulls each object (these objects are stored into an array) down the screen. But, to make the game more interesting, I want the objects to fall down the screen in waves. Like an example:

In the first wave, 4 objects fall down the screen. Then there is a pause of 5 seconds. Then, in the second wave, 8 objects fall down the screen, and there is a 5 sec pause, and then in the third wave, 12 objects fall down the screen and there is a 5 second pause ect. There are an unlimited number of waves, the goal of the app is to see how many wave the user can go without dying.


Any ideas? I imagine that its a very complicated task. Here is some info about the structure of the app (if needed):

An NSTimer Fires every second to generate an object at the top of the screen with a random x value. These objects are stored into an NSMutableArray.

Another NSTimer fires every 1/60 of a second and runs through the MutableArray and pulls the troops down 1 pixel every time the NSTimer is fired.
Kenenth is offline   Reply With Quote
Old 04-25-2011, 02:29 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

It's not complicated at all, and there are definitely multiple solutions. I would choose a very OOP approach and start by defining a "Wave" object.

You just need a way to isolate the properties that define each wave. For instance, the # of objects in the wave could be one property, as well as the length of time to wait before the first object comes down ( this would be the "pause" in between each of the waves that you mention ).

So you could start by defining a few arbitrary waves:
Code:
//this wave will have 5 objects, and would wait 3 seconds before starting
Wave* wave1 = [Wave waveWithObjectCount: 5 andInitialPause: 3];

//this wave will have 3 objects and wait 8 seconds before starting
Wave* wave2 = [Wave waveWithObjectCount: 3 and InitialPause:8];

...// and so on
In order to get your "unlimited" effect, you could create, say 10 different waves and then store them all in an NSArray and just loop through them over and over again.

Now, with y our timer, you would just go through and grab each Wave object out of the array and add your troops to the screen and so forth just like you have been doing.
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nstimer, objects, waves, xcode

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: 352
11 members and 341 guests
dansparrow, iOS.Lover, lorrettaui53, Nobbsy, oztemel, pbart, PlutoPrime, samdanielblr, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,897
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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