Improve cpp-template

Add:
- scheduleUpdate()
- HelloWorld::update(float delta) with some "gamestate switch/cases"
This commit is contained in:
aismann 2023-01-02 22:26:23 +01:00
parent 7d2166fb31
commit 1b35d57b0b
2 changed files with 71 additions and 2 deletions

View File

@ -116,12 +116,64 @@ bool HelloWorld::init()
drawNode->drawRect(safeArea.origin, safeArea.origin + safeArea.size, Color4F::BLUE);
}
return true;
myGameState = myGameState::update;
scheduleUpdate();
return true;
}
void HelloWorld::update(float delta)
{
switch (myGameState)
{
case myGameState::update:
/////////////////////////////
// Add your codes below...like....
//
// UpdateJoyStick();
// UpdatePlayer();
// UpdatePhysics();
// ...
break;
case myGameState::pause:
/////////////////////////////
// Add your codes below...like....
//
// anyPauseStuff()
break;
case myGameState::menu1:
/////////////////////////////
// Add your codes below...like....
//
// UpdateMenu1();
break;
case myGameState::menu2:
/////////////////////////////
// Add your codes below...like....
//
// UpdateMenu2();
break;
case myGameState::end:
/////////////////////////////
// Add your codes below...like....
//
// CleanUpMyCrap();
_director->end();
break;
}
}
void HelloWorld::menuCloseCallback(Ref* sender)
{
// Close the cocos2d-x game scene and quit the application
// Close the axmol game scene and quit the application
_director->end();
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use

View File

@ -28,13 +28,30 @@
#include "axmol.h"
enum myGameState
{
update = 0,
pause,
end,
menu1,
menu2,
menu3,
};
class HelloWorld : public ax::Scene
{
public:
virtual bool init() override;
void update(float delta);
// a selector callback
void menuCloseCallback(Ref* sender);
private:
myGameState myGameState;
};
#endif // __HELLOWORLD_SCENE_H__