• cocos2d‘s replaceScene


    1. new 一个 cocos2d项目

    2. 添加一个场景类

    // .h文件
    #import "CCScene.h"
    
    @interface CCScene_another : CCScene
    
    @end
    
    // .m文件
    
    #import "CCScene_another.h"
    
    @implementation CCScene_another
    
    - (id)init{
        if (self = [super init]) {
            NSLog(@"CCScene_another__init__");
        }
        return self;
    }
    
    - (void)onEnter{
        [super onEnter];
        NSLog(@"CCScene_another__onEnter__");
    }
    
    - (void)onEnterTransitionDidFinish{
        [super onEnterTransitionDidFinish];
        NSLog(@"CCScene_another__onEnterTransitionDidFinish__");
    }
    
    - (void)onExit{
        [super onExit];
        NSLog(@"CCScene_another__onExit__");
    }
    
    @end

    3. 在HelloWorldLayer.m的init中添加一个replaceScene,当然要包含头文件"CCScene_another.h"

     #import "CCScene_another.h"


    - (void)change_scene{ [[CCDirector sharedDirector] replaceScene:[CCScene_another node]]; } // on "init" you need to initialize your instance -(id) init { // always call "super" init // Apple recommends to re-assign "self" with the "super" return value if( (self=[super init])) { NSLog(@"hello__init__"); // create and initialize a Label CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64]; // ask director the the window size CGSize size = [[CCDirector sharedDirector] winSize]; // position the label on the center of the screen label.position = ccp( size.width /2 , size.height/2 ); // add the label as a child to this Layer [self addChild: label]; // replaceScene [self performSelector:@selector(change_scene) withObject:nil afterDelay:0.1f]; } return self; }

    4. 输出信息

    5.结论(下图非自画)

  • 相关阅读:
    树的直径教学思路
    dfs序3树上差分
    DFS序与欧拉序的区别
    DFS序2
    树的重心教学思路
    loadrunner11并发注册码
    JPA 添加 converter
    银行信贷账户管理任务
    《如何启动黄金圈思维》笔记
    《野蛮进化》笔记
  • 原文地址:https://www.cnblogs.com/pure/p/2582460.html
Copyright © 2020-2023  润新知