From 1b35d57b0bbb135120639342da2773b6a7b426ed Mon Sep 17 00:00:00 2001 From: aismann Date: Mon, 2 Jan 2023 22:26:23 +0100 Subject: [PATCH] Improve cpp-template Add: - scheduleUpdate() - HelloWorld::update(float delta) with some "gamestate switch/cases" --- .../Classes/HelloWorldScene.cpp | 56 ++++++++++++++++++- .../Classes/HelloWorldScene.h | 17 ++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/templates/cpp-template-default/Classes/HelloWorldScene.cpp b/templates/cpp-template-default/Classes/HelloWorldScene.cpp index ef3b65565a..da984bc62a 100644 --- a/templates/cpp-template-default/Classes/HelloWorldScene.cpp +++ b/templates/cpp-template-default/Classes/HelloWorldScene.cpp @@ -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 diff --git a/templates/cpp-template-default/Classes/HelloWorldScene.h b/templates/cpp-template-default/Classes/HelloWorldScene.h index b3679cef51..a4da75db9f 100644 --- a/templates/cpp-template-default/Classes/HelloWorldScene.h +++ b/templates/cpp-template-default/Classes/HelloWorldScene.h @@ -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__