#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();

}

Cocos2d-x 3.0 创建一个场景,并设置现场的时候,项目开始执行上主动的更多相关文章

  1. cocos3.2中如何创建一个场景

    1.可以将一些比较通用的东西放到Common.h中,这是一个.h文件,必须手动添加,且保证在classes目录里 #ifndef __COMMON_H__ #define __COMMON_H__ # ...

  2. Three.js入门篇(一)创建一个场景

    上一面讲述了向场景中添加物体对象.这一篇准备把每个功能点细细的讲述一遍,一方面是为了加深自己的理解.另一方面希望能够 帮助到有需要的人. 一.在学习WEBGL的时候,你应该先了解要创建一个WebGL程 ...

  3. 如何创建一个基于 .NET Core 3 的 WPF 项目

    在 Connect(); 2018 大会上,微软发布了 .NET Core 3 Preview,以及基于 .NET Core 3 的 WPF:同时还发布了 Visual Studio 2019 预览版 ...

  4. 使用 Android Studio 开发工具创建一个 Android 应用程序,并在 Genymotion 模拟器上运行

    需求说明: 使用 Android Studio 开发工具创建一个 Android 应用程序,并在 Genymotion 模拟器上运行 实现步骤: 打开 Android Studio,创建一个 Andr ...

  5. 【原创】使用.NET Core 1.0创建一个Self-Contained控制台应用

    开发机器:win7-x64 .NET Core版本:1.0.0-preview2-003121 Visual Studio Code:1.2.1 至于什么是Self-Contained应用类型以及与P ...

  6. [翻译] 使用 .NET Core 3.0 创建一个 Windows 服务

    原文: .NET Core Workers as Windows Services 在 .NET Core 3.0 中,我们引入了一种名为 Worker Service 的新型应用程序模板.此模板旨在 ...

  7. 用 eclipse 创建一个简单的 meaven spring springMvc mybatis 项目

    下面是整体步骤: 1: 先创建一个Maven 项目: 选择跳过骨架: 因为要搭建的是 web 项目  所以这个地方选择 war 包; 点击完成 这样就完成 Maven项目的搭建: 接下俩 先把 Mav ...

  8. cocos2d-x3.0创建第一个jsb游戏

    第一步: 最新的cocos2d-x.下载地址https://github.com/cocos2d/cocos2d-x github上最新的引擎,值得注意的是官网上发布的引擎是稳定版.选择哪种就看个人喜 ...

  9. swift3.0 创建一个app引导页面

    swift毕竟不像是oc ,第三方的框架很多,更何况是3.0,自己动手写了个引导页面,看得上我代码的麻友可以拿去用 引导页面有三个部分构成,scrollview用语切换引导视图,pageControl ...

随机推荐

  1. [置顶] getline函数-linux

    头文件: #include <stdio.h> 函数: ssize_t getline(char **lineptr, size_t *n, FILE *stream); eg: ssiz ...

  2. PHP - 接口 - 多接口

    /* * 使用多接口 */ //定义接口1 interface IPerosn_one{ public function eat(); } //定义接口2 interface IPerson_two{ ...

  3. Opera浏览器测试移动端网站和模拟手机浏览器的方法

    链接地址:http://www.neirong.org/post-256.html?utm_source=tuicool Chrome浏览器请看:Chrome浏览器测试移动端网站和模拟手机浏览器的方法 ...

  4. 查看ORACLE事务隔离级别方法(转)

    众所周知,事务的隔离级别有序列化(serializable),可重复读(repeatable read),读已提交(read committed),读未提交(read uncommitted).根据隔 ...

  5. JAVA UTF-8字符转换为GBK

    String t = "\u53d6"; try { String gbk=URLEncoder.encode(t,"GBK"); System.out.pri ...

  6. 在TC(Total Commander)中添加启动Cygwin快捷键的方法

    在TC(Total Commander)中添加启动Cygwin快捷键的方法 1.在Cygwin的安装目录下,增加文件tc-cygwin.bat(例如C:\cygwin-177\tc-cygwin.ba ...

  7. ZJUT 1423 地下迷宫(期望DP&高斯消元)

    地下迷宫 Time Limit:1000MS  Memory Limit:32768K Description: 由于山体滑坡,DK被困在了地下蜘蛛王国迷宫.为了抢在DH之前来到TFT,DK必须尽快走 ...

  8. jQuery Validation让验证变得如此easy(一)

    一.官网下载jquery,和jquery validation plugin http://jqueryvalidation.org/ 二.引入文件 <script src="js/j ...

  9. Redhat下安装fedora

    步骤具体解释: 1:到fedora官网下载fedora的DVD镜像文件. 2:在linux系统中预留一部分为未分区的空间大约50G 3:   在linux系统上的根分区创建一个fedora的目录,里面 ...

  10. Swift - 通过设置视图的transform属性实现动画

    设置视图对象的transform属性,可以实现各种动画效果. 1,移动 指在同一平面内,将控件按照某个直线方向平移一定的距离. 1 2 3 4 5 //每次都从当前位置平移 self.imageVie ...