zoukankan      html  css  js  c++  java
  • Cocos2d-x 3.0 创建一个场景,并设置现场的时候,项目开始执行上主动

    #ifndef __TEST_H__
    #define __TEST_H__


    #include "cocos2d.h"
    USING_NS_CC;


    class Test : public Layer
    {
    public: //不要忘记public不然默觉得private的不能正常执行
    static Scene * createScene();
    virtual bool init();
    CREATE_FUNC(Test);
    };
    #endif //__TEST_H__


    源文件

    #include "Test.h"
    USING_NS_CC;


    Scene * Test::createScene()
    {
    auto scene = Scene::create();
    auto layer = Test::create();
    scene->addChild(layer);
    return scene;
    }
    bool Test::init()
    {
    if (!Layer::init())
    {
    return false;
    }


    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();


    auto label = LabelTTF::create("Hello World", "Arial", 24);
    label->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height - label ->getContentSize().height));
    this->addChild(label, 1);
    return true;
    }

    然后在AppDelegate.cpp中。加入头文件


    #include "AppDelegate.h"
    #include "HelloWorldScene.h"


    #include "Test.h"  //加入头文件


    USING_NS_CC;


    AppDelegate::AppDelegate() {


    }


    AppDelegate::~AppDelegate() 
    {
    }


    bool AppDelegate::applicationDidFinishLaunching() {
        // initialize director
        auto director = Director::getInstance();
        auto glview = director->getOpenGLView();
        if(!glview) {
            glview = GLView::create("My Game");
            director->setOpenGLView(glview);
        }


        // turn on display FPS
        director->setDisplayStats(true);


        // set FPS. the default value is 1.0/60 if you don't call this
        director->setAnimationInterval(1.0 / 60);


        // create a scene. it's an autorelease object
        //auto scene = HelloWorld::createScene();
    auto scene = Test::createScene();  //实例化场景


        // run
        director->runWithScene(scene); //把实例化的场景名加进来就能够了


        return true;
    }


    // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
    void AppDelegate::applicationDidEnterBackground() {
        Director::getInstance()->stopAnimation();


        // if you use SimpleAudioEngine, it must be pause
        // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
    }


    // this function will be called when the app is active again
    void AppDelegate::applicationWillEnterForeground() {
        Director::getInstance()->startAnimation();


        // if you use SimpleAudioEngine, it must resume here
        // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
    }


























  • 相关阅读:
    DataTablez转List对象效率慢的问题.
    Oracle 删除重复数据
    1.layui 添加旋转等待, 2.div里面加载HTML页面
    layui-table JSON.stringify()序列化出来的不同行数据类型错误.导致后台转成表格的时候出错.(常用)
    0基础学MVC课程
    构造函数的执行顺序
    html控件自动点 “加号”添加 多个附件
    C#委托之个人理解 转自 loose_went
    一步一步学Linq to sql系列文章 转lovecherry
    使用AOP 使C#代码更清晰 转yanghua_kobe
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4586329.html
Copyright © 2011-2022 走看看