i have created iphone game.When i pause the game using pause button i quit cliking quit button...
Now when i start the game again ..the previous counter i created using this code...
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(updateTimerFunc) userInfo:nil repeats:YES];
the timer is 100 sec and moves to zero...now it start giving the difference of twwo ,,98,96,94
if i quit the game again ans start this time the difference will become of 4 96,92 ...its keep on increasing ....what is this issue?
kindly help
Sounds like "multi-tasking" and improperly placed initialization code.
You may not actually be "exiting" your application when you think you are. Double check that the application is not still running in the background after you press the "home" button.
Also, it could have something to do with your "quit" button as well - where it is not actually "quitting" but rather putting the application into the background?
Related
So I made a little game (console app) and at the end I wanna display an end game screen. If the player dies while trying to move somewhere they'll be in the middle of pressing a key. My solution that uses _getch() to halt the console will catch that key and instantly close the console without giving the player a chance to see what happened. It makes it look like the game crashed.
I need something time based, that doesn't react to any keys for a few seconds, but then does.
int main()
{
//game loop is here somewhere, exits when player is dead
if (player.isDead())
{
displayGameOverScreen();
return 0;
}
}
void displayGameOverScreen()
{
std::cout << "You died.";
_getch();//if player is still pressing keys
//console instantly closes
}
I assume you are working under Windows, so you can put Sleep(2000) for 2 seconds of sleep or better solution if you close the window when user press directly a button that reserved for, like 'Q' letter and 'R' is could be for retry / restart in this case, let the game re-initialise itself and remove return statement after displayGameOverScreen().
Problem with Sleep when the users press a key while in its sleeping, the key press will have effect immediately after sleep have done.
After displayGameOverScreen();
add system("pause");
and the screen should be frozen on the spot and will not close.
If that doesn't work, add Sleep(4000); instead of system("pause");
and it will stay for 4 seconds before closing.
Keep in mind that you should add #include<Windows.h>
I need a wait cursor to be loaded when the second page OnWizardNext of a property sheet is clicked .This is how I had done.Actually I designed a property sheet and now when I Click on the Next button I had activated the hourglass ,till this point everything works fine ,here arises the actual problem i.e,during that wait cursor period if I click again on Next button the dialog is getting dismissed .So,my intention is even if I click Next during the wait cursor it should not react to the click event.
LResult OnWizardNext()
{
CWaitCursor wait_cursor();
Sleep(10000);
return CPropertyPage::OnWizardNext()
}
if I remove Sleep then no wait cursor is getting loaded.What I need is even though if click on any button anything the event for that button should not get triggered until unless i am out of sleep time.
Can anyone please let me know how to achieve this.
I think you have a problem with the design of your wizard. You should not be using "Sleep" as it will suspend the thread. Moreover, the wait cursor is nothing more than a UI mechanism to indicate to the user that the code is still active. You seem to want to use that as a determinant for when your code can continue. Take a look at using OnSetCursor to provide visual feedback. Depending on what it is you're waiting on, you may want to look at using a timer, or, perhaps a series of "flags" to indicate a "continue" condition.
How to pause a game in cocos2d android? I searched many tutorials but i did not found anywhere.I tried below code, it is working when paused from game scene.But it not working while resuming the game from pause scene
in gameScene :
CCDirector.sharedDirector().onPause();
in pause Scene :
CCDirector.sharedDirector().onResume();
For pausing game scene I use:
CCDirector.sharedDirector().pause();
And for resuming:
CCDirector.sharedDirector().resume();
Try it with these functions. :)
Thanks for your reply. I used the same thing.But it wont stop schedulers and actions.
But finally i got the way we have to pause.
1.To pause we have to use pushScene() method as follows:
CCScene pauseScene = CCScene.node();
pauseScene.addChild(new PauseLayer);
CCDirector.sharedDirector().pushScene(pauseScene);
When you have done this, gamescene will get stored in the stack and now running scene will be pause scene.
2.To resume we have to use popScene() as follows:
CCDirector.sharedDirector().popScene();
3.If you are moving to LevelSelection form pause then along with above lines use these lines also:
CCDirector.sharedDirector().getRunningScene().removeAllChildren(true);
CCDirector.sharedDirector().replaceScene(levelSelectScene);
Declare a BOOL variable, then when you detect user pauses game, make this variable to NO and in your update method put this as a condition above to the code you want to pause on your game paused.
-(void)update:(ccTime)dt
{
if(isGameNotPaused)
{
// your code
}
}
i am working with cocos2d game with GameKit. I am creating match with 2 player using GKMatch. All thing is working fine for me but When one player enters the background state or pressing home button , then player is disconnected. I want to run GKMatch instance in background also. Please help me.
Thanks in advance.
I don't think that's possible, after all "background" means the player stopped playing.
While the programming guide might not mention that explicity, it does one thing, namely automatically logging in the player when the application enters foreground, which to me indicates there's simply no player GKMatch could be connected with while the app is in the background.
My question in the previous post was-
I have a cocos2d game, and after I
exit the game and start it again, it
starts at the exact same point it was
before closing.why this is
happening??and not only this, my game
is landscapemode but when I start it
again from simulator it comes in
portrait mode,not it landscapemode like
first time.
Is there any way to prevent this?
Anyone will come to rescue me???
I found a solution.Is it good??
when I exit the game(by pressing the back button in iPhone simulator) this problem occurred. Now I found that if I press back button the following function is called-
(void)applicationWillResignActive:(UIApplication *)application
So I set (divide by zero) or something like this in -(void)applicationWillResignActive function so that when this function called the application crashes. Then if I restart the application everything comes from beginning(reset) which I want. Is it good solution or anything better?
*my applicationDidFinishLaunching was not called again when application is restart from simulator.
You should configure the Info.plist to indicate that you does not want your application run in Background.
The key is
UIApplicationExitsOnSuspend
If you need more detail you should look at this tutorial
If you have iOS 4.0 or higher, multitasking is causing your problem.