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
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.
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).
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.
*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:
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.
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.