- 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.
- Learning Single:page Web Application Development
- 多媒體CAI課件設計與制作導論(第二版)
- ClickHouse性能之巔:從架構設計解讀性能之謎
- AngularJS Testing Cookbook
- INSTANT OpenCV Starter
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- Python從入門到精通(精粹版)
- The React Workshop
- 算法精粹:經典計算機科學問題的Python實現
- 小程序,巧運營:微信小程序運營招式大全
- 量化金融R語言高級教程
- Raspberry Pi Home Automation with Arduino(Second Edition)
- Java Web開發詳解
- Java SE實踐教程
- 機器學習微積分一本通(Python版)