0
votes

I have a fully functioning game, with Sprites Actions etc. But at a certain point the scene needs to be restarted.

Whenever I load up the game, I call a method in didMoveToView called createSceneContents. In createSceneContents I create everything that needs to be created (Sprites, Labels etc..).

However, when I want to restart the game entirely how do I do this?

1
Sounds like you either need to have your code organized in a way to reset all assets to their starting positions or transition the current scene to a new one with code to auto load the game scene again.sangony
Thanks for that suggestion, gonna play around with those ideas for a little bit and I'll be backSemAllush
When you init everything, don't set it up in the viewDidLoad directly, instead create a function that creates everything and sets up the scene. When time to 'recreate' the scene, call the [self removeAllChildren] method which will delete all existing nodes, and call the method to create contents again.Andriko13

1 Answers

1
votes

Create a method that contains two things.

1) Delete everything that is being used ATM (All the sprites, actions, labels etc...)

2) Create everything over using your createSceneContents method

Code:

- (void) restart {

[self removeAllChildren];
[self removeAllActions];
[self createSceneContents];
}

Just call this method whenever you want to restart your scene