Could someone help me figure out how to safely stop all actions when closing a Win32 cocos2dx app that is running CCRepeatAction. I have tried adding sprite->stopAllActions(); in the Destructor, OnExit() and in the update(float delta); methods but still app crashes when I click on the 'X' button of my running Win32 Cocos2dx app.
I am not retaining the CCRepeatAction and I have also tried just letting Cocos2D-X stop the running action when it does its cleanup, but it seems like if a CCAction is running while app is closed then app crashes. So my assumption is that the action has to be stopped when closing the Win32 App.
The repeat forever action is running on my idle state. It is a simple fadeIn/fadeOut CCAction. Here is the code for my Idle state animation. I am not retaining it so not sure how to stop the animation and close the app without crashing it.
if ( idleAnim == true )
{
this->getSprite()->stopAllActions();
CCSequence *actions = CCSequence::create(CCFadeIn::create(0.5f), CCFadeOut::create(0.5f),NULL);
CCRepeatForever *repeat = CCRepeatForever::create(actions);
this->getSprite()->runAction(repeat);
idleAnim = false;
}
Related
I don't want to deflect the button hit or ignore the close event. I just need to run some cleanup code.
Let me tell you what I've tried so far:
atexit()
_onexit()
SetConsoleCtrlHandler()
~QCoreApplication()
No code set by these is being executed.
The process just get killed when I press the X.
I certainly can make a windowed app and solve this, but is there a solution for a console application?
Thanks!
I'm trying to delay a Right Button click using C++,
Right now I have
if (GetKeyState(VK_LBUTTON) > 0) {
delay(120);
}
It works fine but while it's executing the program freezes.
Is there a way I can make it delay the click but without freezing the Program?.
If you want to delay when an action occurs, then you should set a timer for it. Your program shouldn't just delay because it still needs to handle mouse events and graphics during that time. By setting a timer, the action will occur at the appropriate time without the rest of the program freezing.
Here's the microsoft guide on using timers: https://learn.microsoft.com/en-us/windows/desktop/winmsg/using-timers
This is probably a silly wx newbie question, but I'm new to this IDE.
When using the wxTimer, adding it to a wxFrame, it runs on startup. I can Stop it and Start it after my app launches, but initially it runs.
Using the wxTimer starts with adding it to a wxFrame. Then double-click the new wxTimer control icon to create an event as such:
void wxSQLi_417Frame::OnTimer1Trigger(wxTimerEvent& event)
{
DisUpdate();
}
This now fires with adding a Timer1.Start();
How can it be idle on startup, until sending a
Timer2.Start();
?
From the documentation:
In any case, you must start the timer with wxTimer::Start() after
constructing it before it actually starts sending notifications.
So if your timer is running, you must have started it explicitly.
I am having a application in cocos2d-x. I want my application should run always until manually stops. But while enters into the background it got paused and when return back it resumes. I removed the codes
CCDirector::sharedDirector()->pause();
CCDirector::sharedDirector()->resume();
from Appdelegate.cpp functions (applicationDidEnterBackground() and applicationDidEnterForeground()). But still my application got pause while enter into background.I want my application should pause only when i got a phone call or manually i pause my application, until or unless it should run in the background. Please me to solve this.
Here is what happens when your app goes to background
class name >>> Cocos2dxActivity.java
#Override
protected void onPause() {
super.onPause();
Cocos2dxHelper.onPause();
this.mGLSurfaceView.onPause();
}
I think the code is self explanatory,i.e, it is pausing your app when it enters background (the whole purpose of onPause) and the ApplicationDelegate methods you mentioned are just JNI functions called when the activity goes to background/foreground so that you can do game related stuff there. As you may know that CCDirector's pause only pauses the running scene (scheduled timers) and changes the draw rate to 4 FPS to reduce CPU consumption.
So, removing pause/resume calls to CCDirector in Appdelegate will not help achieve those goals. For that you have to override the method and related methods I mentioned above and stop the activity from pausing.
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?