zoukankan      html  css  js  c++  java
  • 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.结论(下图非自画)

  • 相关阅读:
    SVG 2D入门11
    SVG 2D入门13
    jetty
    jquery 跨域访问问题 转
    js 读取 地址栏参数 转
    油猴 greasemonkey 背景音乐 火狐 chrome 背景音乐
    火狐 about:config
    js javascript 模拟点击 超级链接点击 转
    PostgreSQL的时间/日期函数使用 转
    update 多表
  • 原文地址:https://www.cnblogs.com/pure/p/2582460.html
Copyright © 2011-2022 走看看