I am developing a game using cocos2d-x. I want to pause the particular scene, when user press the pause button.
Thanks.
You can pause a particular scene in two different ways
1.) Use CCDirector::sharedDirector()->stopAnimation(); to pause and CCDirector::sharedDirector()->startAnimation(); to resume.
2.) Use CCDirector::sharedDirector()->pause(); to pause and
CCDirector::sharedDirector()->resume(); to resume.
Related
I am creating a game for iOS. The game is written as a C++ library so that it can be ported to another platform. I am also using Swift and Objective C to call the game update, draw functions and process user input etc. in the view controller.
I am having and issue where the game begins to stutter when I press a UIButton to perform some action in the game. I have noticed even when the UIButton callback function is empty, the game still stutters.
The game idles at ~30% CPU usage. When I press the button, the cpu usage drops to ~15% for a few seconds, then gradually makes its way back up 30%. It's during this time that the game stutters.
It seems to me that when the button is pressed, the operating system is allocating fewer resources to the app, causing it to slow down.
To try and resolve this problem, I have put the game update function on a new thread to take some weight off the main thread. This did not work.
Any idea what could be causing this?
I have a game in Cocos2d with a main scene (game scene) and a button to go to a "Configuration" scene. When the user clicks on the Configuration button in the main scene I use pushScene to go tho the "Configuration" scene. The reason I use pushScene is to allow the user to resume the game where he was left off.
In the "Configuration" scene there are two options: "Cancel" and "Ok". If the user hits "Cancel" I use popScene and the game resumes where it was left of. If the user hits "Ok" I use replaceScene because I want the game to start from the beginning with the new configuration.
So, when the user hits "Ok" I know that the "Configuration" scene is replaced by the new game scene, but does the old game scene gets replaced too? Otherwise, am I doing things correctly or should I implement another way to let the game scene know whether it should resume or restart.
I want to make sure I am not leaking memory by accumulating unreplaced scenes.
The replaceScene method does what it says. It replaces the current scene. If you have 10 scenes pushed onto one another, it will replace the 10th scene and all previous scenes remain.
It's one of the reasons why I don't recommend using pushScene. It's too easy to forget a situation where scenes might get pushed more than they get popped. The other reason is that popScene can't be animated with a transition.
Btw, you can easily test this behavior if you do replaceScene after pushScene, then popScene in the newly replaced scene. You'll see the old scene popping up. Normally if you popScene with just a single scene in the stack it'll throw an assertion.
I am close to finishing my first cocos2d game. Now I want to make a small movie/story to show when the user launches the game app. The game should first show the 15 seconds story (animated story) like in MonsterShooter, JailBreaker, AngryBirds, or the like. When you tap on the story, it takes you to the main menu.
My question is: What to use to make the story? Other than making an actual scene with lots of animations is there any other tool that I can use to create an animated story and embed it to cocos2d layer?
What you need to do is to make a video, you could try with adobe premiere, final cut, Windows Movie Maker, iMovie, adobe after effects (just to name a few), then to play the video use the CCVideoPlayer from cocos2d-iphone-extensions
i want to pause my game i used the following code but its not pausing when we return from any interrupt its shows the main menu screen.its starting from 1st again.
It is expected that if user gives any sort of interrupt during action phase of the game then after returning back from the interrupt game should pause at the exact location where interrupt occurred displaying pause screen with required options.
CCDirector.sharedDirector().pause();
I got this issue solved. The problem is with the screen orientation change. The game is in landscape mode, when the device sleeps the screen orientation automatically changes to portrait mode. This results in restarting the activity.
Adding android:configChanges="keyboard|keyboardHidden|orientation" to the activity in the manifest solves the issue.
I am developing an iOS game using Cocos2D. I would like to show a popup, something like UIAlertView, but completely custom. What is the best way to achieve this?
Thanks a lot!
Benza
I would suggest to use a layer for this and to pause the scene. Here are a couple forum posts from the Cocos2d site that go over this a bit:
http://www.cocos2d-iphone.org/forum/topic/6511
http://www.cocos2d-iphone.org/forum/topic/1954
Unfortunately pausing the scene means you will also pause whatever you have in your popup.
Maybe it's not your case, but I quite often have scrolling lists in my popups. If I pause the scene it will not work.
I've added a method to CCNode which goes through all children and stops their activity rather than pausing the scene.
If you open the popup as a child of your scene then first you deactivate all children of the scene and then open the popup. This means that you can still do whatever you want in your popup and everything else is paused or does not respond to touch [like menus].