- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Siddharth Shekar
- 183字
- 2021-07-16 09:43:49
Transitioning between scenes
We will discuss how to transition between scenes in this section.
Getting ready
Most of the work is already done in the previous section, so let's dive right into creating the code. However, as we want to transition into GameplayScene
, we have to import the class into the MainScene.m
file, as follows:
#import "GameplayScene.h"
How to do it…
Next, add the following highlighted code to the playBtnPressed
function in the MainScene.m
file:
-(void)playBtnPressed:(id)sender{ CCLOG(@"play button pressed"); [[CCDirector sharedDirector] replaceScene: [[GameplayScene alloc] initWithLevel:@"1"]]; }
How it works…
Now, when we press the play button, GameplayScene
will load, display the GameplayScene
text, and show that it has loaded level 1.

There's more…
We added a reset button and a function that will take us to MainMenu
in GameplayScene
. So, we will change the resetButtonPressed
function in GameplayScene.m
as follows so that when we press the reset button, the scene will transition to the MainMenu
scene:
-(void)resetBtnPressed:(id)sender{ CCLOG(@"reset button pressed"); [[CCDirector sharedDirector] replaceScene:[[MainScene alloc] init]]; }
Run and press the reset button to go back to the main menu now.
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- What's New in TensorFlow 2.0
- Getting Started with ResearchKit
- Python數據可視化:基于Bokeh的可視化繪圖
- Python從入門到精通(精粹版)
- HTML5 Mobile Development Cookbook
- Visual Basic程序設計教程
- 精通API架構:設計、運維與演進
- Building Cross-Platform Desktop Applications with Electron
- C語言實驗指導及習題解析
- 精通網絡視頻核心開發技術
- Modern JavaScript Applications
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- Creating Stunning Dashboards with QlikView
- C語言開發基礎教程(Dev-C++)(第2版)