i m using cocos2d and i want to change scene to replay the game when the player touches the end scene so that it starts the game again.
I just stuck to use touch event on [[CCDirector sharedDirector]replaceScene:[CCTransitionZoomFlipAngular transitionWithDuration:2 scene:scene orientation:kOrientationLeftOver]];
Please Help
Thanks in advance
Don't ever send an existing, running scene to be replaced. Create a new instance of the same scene class if you want to restart the scene.
Related
When the game over condition is satisfied I want to show a game over menu. This menu I have implemented via Scene. Now I wonder how I can show game over scene on top of ingame, without covering all the ingame scene. I want to make it look like a popup. How I should do that?
Checkout part "Design and Implement the Game Over Layer" in the following tutorial at: http://www.cocos2d-x.org/docs/tutorial/parkour-game-with-javascript/chapter9/en
It wrote in js, but i think the process with Cpp is the same.
I'd say just change your CCScene to CCLayer. Very few changes will be required in the code.
Then the part where you use the CCDirector to replace scene with your Game Over scene just initialize your Layer.
I don't get why this code is incorrect...
DeadPanelLayer* deadPanelLayer = [DeadPanelLayer node];
[(CCScene*)self.parent addChild:deadPanelLayer z:2];
DeadPanel is a layer that I want to add on the Scene running from another layer
any idea why my layer is not loaded?
Edit: the game is not crashing, but the new layer does't show up. I tried to even move the objects on the scene and layer just to make sure it is not displaying due zindex hierarchic
but still...
I tried to add a method on Scene to add the layer in case it is called from parent:
[(GameScene*)self.parent showDeadPanel];
and even get current scene from Director
[[CCDirector sharedDirector] runningScene]
and it doesn't work either
in cocos2d I need to drag a sprite in my project using finger. how do i get hold of that sprite? any help will be appreciated. thanx. i am using chipmunk engine.
You need to capture the touch began, work out what sprite is being touched and then track the movement of the touch. In touches moved you update the position of the sprite.
Sound complicated? It's not really. Here is a great tutorial for it.
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
I have created a game of two levels.Now when we are in level one i create sprite sheet for animation and a lot of sprites.On reaching a certain score i move to level 2 now here here is another sprite sheet and a lot of variables.
When i am moving from level 1 to level 2 using.
[[CCDirector sharedDirector] pushScene:[Level2 node]];
when i lose on level 2 i move back to level 1 using
[[CCDirector sharedDirector] pushScene:[Level1 node]];
What happens to the sprite sheet and other sprites i created before on level 1 ? If i retry level 1 will the sprite sheet and sprites i created before be removed automatically ?or they will exists in this new scene?
kindly clear me these issue i am having a lot of trouble because of no understanding of this..
thank you in advance.. :(
In cocos2d almost everything is marked as autorelease. So when you create a new scene it is not released because it becomes the main scene. Once it is no longer the main scene, if you do not specifically retain it then it will be released.
In the case you state above I believe that both scenes are retained as you are using the director like a stack, pushing the scenes on each other. If you never need to go back to level 1 you can use CCDirector's replaceScene: method instead to release level 1.
Having a custom pause scene or bonus round might be a good example of when to use the pushScene: call.
I want to restart the current scene i am on. I thought of using replaceScene and replace it with itself. Is that ok to do ?
Level2Scene *scene = [Level2Scene node];
[[CCDirector sharedDirector] replaceScene:scene];
Level2Scene is the current scene I am in.
Thanks
Abhinav
Using replaceScene: is a good way to restart the level, if levels are represented by scenes. Just make sure that if you have any global state (stored outside of the scene) that you reset that, too.