Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97e2d3d

Browse files
Initial loading layer (#74)
* Function to CreateRectangle. Function to InitializeAuthenticaionLayer. Function to InitializeLoginLayer. Function to InitializeSignUpLayer. * Adding Loading layer that swaps after a delay.
1 parent 5049a9f commit 97e2d3d

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

‎demos/TicTacToe/game_resources/Classes/main_menu_scene.cc‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static const char* kJoinButtonImage = "join_game.png";
6767
static const char* kLoginButtonImage = "login.png";
6868
static const char* kLogoutButtonImage = "logout.png";
6969
static const char* kSignUpButtonImage = "sign_up.png";
70+
static const char* kLoadingBackgroundImage = "loading_background.png";
7071

7172
// Regex that will validate if the email entered is a valid email pattern.
7273
const std::regex email_pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
@@ -89,6 +90,10 @@ bool MainMenuScene::init() {
8990
// Initializes the firebase features.
9091
this->InitializeFirebase();
9192

93+
// Initializes the loading layer by setting the background that expires on a
94+
// delay.
95+
this->InitializeLoadingLayer();
96+
9297
// Initializes the authentication layer by creating the background and placing
9398
// all required cocos2d components.
9499
this->InitializeAuthenticationLayer();
@@ -637,6 +642,29 @@ void MainMenuScene::InitializeLoginLayer() {
637642
});
638643
}
639644

645+
// Creates and places the loading background. Creates a action sequence to delay
646+
// then swap to the authentication state.
647+
void MainMenuScene::InitializeLoadingLayer() {
648+
// Creates the delay action.
649+
auto loading_delay = DelayTime::create(/*delay_durration*/ 2.0f);
650+
651+
// Creates a callback function to swap state to kAuthMenuState.
652+
auto SwapToAuthState =
653+
CallFunc::create([this]() { state_ = kAuthMenuState; });
654+
655+
// Runs the sequence that will delay followed by the swap state callback
656+
// function.
657+
this->runAction(Sequence::create(loading_delay, SwapToAuthState, NULL));
658+
659+
// Creates the loading background sprite.
660+
const auto window_size = Director::getInstance()->getWinSize();
661+
const auto background = Sprite::create(kLoadingBackgroundImage);
662+
background->setContentSize(window_size);
663+
background->setAnchorPoint(Vec2(0, 0));
664+
loading_background_ = background;
665+
this->addChild(loading_background_);
666+
}
667+
640668
// 1. Creates the background node.
641669
// 2. Adds the layer title label: authentication.
642670
// 3. Adds the id and password text fields and their event listeners.
@@ -843,11 +871,11 @@ void MainMenuScene::update(float /*delta*/) {
843871
assert(0);
844872
}
845873
}
846-
// Returns kAuthMenuState. This will be the default update method and
847-
// immediately swap to auth state. TODO(grantpostma): have this display a
848-
// loading screen before swapping.
874+
// Returns kInitializingState. Waits for the delay action sequence to callback
875+
// SwaptoAuthState() to set state_ = kAuthMenuState.
849876
MainMenuScene::kSceneState MainMenuScene::UpdateInitialize() {
850-
return kAuthMenuState;
877+
this->UpdateLayer(state_);
878+
return kInitializingState;
851879
}
852880

853881
// Updates the layer and returns the kAuthMenuState.
@@ -964,4 +992,5 @@ void MainMenuScene::UpdateLayer(MainMenuScene::kSceneState state) {
964992
auth_background_->setVisible(state == kAuthMenuState);
965993
login_background_->setVisible(state == kLoginState);
966994
sign_up_background_->setVisible(state == kSignUpState);
995+
loading_background_->setVisible(state == kInitializingState);
967996
}

‎demos/TicTacToe/game_resources/Classes/main_menu_scene.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class MainMenuScene : public cocos2d::Layer, public cocos2d::TextFieldDelegate {
8787
// screen.
8888
void InitializeUserRecord();
8989

90+
// Initializes the loading layer which includes a background loading image and
91+
// state swap delay action.
92+
void InitializeLoadingLayer();
93+
9094
// Initializes the game menu layer which includes the background, buttons
9195
// and labels related to setting up the game menu.
9296
void InitializeGameMenuLayer();
@@ -129,6 +133,9 @@ class MainMenuScene : public cocos2d::Layer, public cocos2d::TextFieldDelegate {
129133
// Node to be used as a background for the sign-up menu.
130134
cocos2d::DrawNode* sign_up_background_;
131135

136+
// Node to be used as a background for the loading layer.
137+
cocos2d::Sprite* loading_background_;
138+
132139
// Labels and textfields for the authentication menu.
133140
Label* login_error_label_;
134141
Label* sign_up_error_label_;
42.5 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /