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-21-2010, 10:01 AM   #1 (permalink)
Banned
 
Join Date: Dec 2009
Posts: 61
Default Annoying bug - help appreciated

Hi,

I have a game where power-ups are created and fall down the screen for the player to collect. When a power-up is collected, a method is fired to create a new one to be dropped later in the game. When a new game is started, another power-up is created (incase the player has missed the previous one). This is all ok, unless the player collects the previous power-up (thus creating a new one) and then dies while it is activated (creating a second power-up). If the game is then restarted, TWO power-ups fall at the same time. I assumed that the obvious answer was to clear the game of power-ups before creating one when the game starts
Code:
[powerArray removeAllObjects]; [self createPower];
, or to not create a second one unless the array is empty
Code:
if (powerArray.count <1) {[self createPower];}
, but neither of these methods seem do have any effect.

Thanks
iPhoneDevelopment is offline   Reply With Quote
Old 03-24-2010, 04:19 AM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

How are you storing powerArray? Are you sure powerArray is being created correctly on startup? Both of the code snippets you posted should have an effect, but it's hard to say without knowing more about what you are doing, and more details of exactly what is going wrong.
JasonR is online now   Reply With Quote
Old 03-24-2010, 05:51 AM   #3 (permalink)
Banned
 
Join Date: Dec 2009
Posts: 61
Default

Thanks for the response. I create the power-up like this:
Code:
-(void)createHigherPower {
	
	if (powerArray==nil){
		powerArray = [[NSMutableArray alloc] init]; }
	
	UIImage *higherImage = [UIImage imageNamed:@"Higher.png"];
	UIImageView *higher;
	
	higher = [[UIImageView alloc] initWithImage: higherImage];
	int higherx = arc4random()%320; 
	int highery = -50;
	higher.center = CGPointMake (higherx,highery);
	
	[self.view insertSubview:higher belowSubview:showPause];
	[powerArray addObject:higher];
	[higher release]; 
}
An I call '[self createHigherPower]' in my 'viewDidLoad' method and every time a power-up is collected (so that it is ready to be animated down the screen for the player to collect later in the game). I also, however, have to call it when a new game has started, incase a previous power-up has been missed, and herein is my problem: if a power-up is collected just before the player dies, a new one is created off-screen, then if a new game is started, another power-up is created, and so during the new game they fall together at the same time.

I assumed that by using the methods posted above in my 'reset' method (called when a new game is started), it would either get rid of the old power-up before it created a new one, or not create a new one if there was already an existing one, but this doesn't seem to work (and haven't got a clue why).

I hope this clarifies things.

Thanks
iPhoneDevelopment is offline   Reply With Quote
Old 03-24-2010, 06:01 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Have you stepped through in the debugger to make sure all the steps are being run? What does it show for the contents of powerArray after calling [powerArray removeAllObjects]? Somehow I think that line is being skipped, because it does not make sense otherwise.
JasonR is online now   Reply With Quote
Old 03-25-2010, 05:29 AM   #5 (permalink)
Registered Member
 
AptoTech's Avatar
 
Join Date: Mar 2010
Posts: 29
Default

*I am the same person as iPhoneDevelopment, but this is my new account*

I have gone around and around in circles trying to work out what is happening, and I think I may have come up with an answer. When the power up is collected, I call '[self higher];', which fires this method:
Code:
-(void)higher {
	jumpStrength = 28;
	[self performSelector:@selector(normalJump) withObject:nil afterDelay:10];
}
Am I right in thinking then that this method will continue to run for 10 seconds? If I am, then if the player die during those ten seconds, that method will still be running? I have a hunch that this may be the source of the problem.
__________________

AptoTech.com - Our website!
Twitter Feed - Follow us on Twitter!
YouTube Channel - Trailer coming soon!
Facebook Fan Page - Why not become a fan?
Jump! - an intensive, addictive and engrossing jumping game! - Out now for the iPhone and iPod Touch!
Jump! Lite - The free version of my first game!
AptoTech is offline   Reply With Quote
Old 03-28-2010, 09:43 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Yes, the performSelector will be run after 10 seconds no matter what. Either check if the user is dead at the beginning of that function, or switch to using a timer so you can cancel it.
JasonR is online now   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: 354
21 members and 333 guests
ADY, Dani77, Duncan C, e2applets, Grinarn, HemiMG, Herbie, JasonR, keeshux, linkmx, macquitzon216, mer10, Monstertaco, prchn4christ, Promo Dispenser, Robiwan, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,881
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, macquitzon216
Powered by vBadvanced CMPS v3.1.0

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