Five mobile game development artifact cocos2d-x editor scene Switch

Source: Internet
Author: User

Next, in the previous section, we have created a main game scenario MainLayer. Now we need to create a start scenario StartLayer, including StartLayer. ccbx and StartLayer. js files. Click the start button on StartLayer to switch the game to the main game scenario. OK. Let's get started;

First, create the StartLayer. ccbx and StartLayer. js files, such as operations (sources right-click ---- new --- layer) (sources right-click --- new --- controller)




After the controller is created, specify the controller;



We designed the starting scene, a color background layer, and a MenuItem button;





After the scenario design is complete, we start programming StartLayer. js. We only need to add a function onPlayClicked () and click player to jump to MainLayer. js;

//// CleanerScoreScene class//var StartLayer = function () {    cc.log("StartLayer")};StartLayer.prototype.onDidLoadFromCCB = function () {//    this.rootNode.onUpdate = function (dt)//    {//        this.controller.onUpdate();//    };//    this.rootNode.schedule(this.rootNode.onUpdate);    if (sys.platform == 'browser') {        this.onEnter();    }    else {        this.rootNode.onEnter = function () {            this.controller.onEnter();        };    }    this.rootNode.onExit = function () {        this.controller.onExit();    };};StartLayer.prototype.onEnter = function () {}StartLayer.prototype.onUpdate = function () {}StartLayer.prototype.onPlayClicked = function () {    cc.BuilderReader.runScene("", "MainLayer");}StartLayer.prototype.onExit = function () {}

Then set Main. js to enable the Main function to start StartLayer first. Also, do not forget to add this line of code require ("StartLayer. js ");

if (sys.platform == 'browser') {    var require = function (file) {        var d = document;        var s = d.createElement('script');        s.src = file;        d.body.appendChild(s);    }} else {    require("jsb.js");}cc.debug = function (msg) {    cc.log(msg);}cc.BuilderReader.replaceScene = function (path, ccbName) {    var scene = cc.BuilderReader.loadAsSceneFrom(path, ccbName);    cc.Director.getInstance().replaceScene(scene);    return scene;}cc.BuilderReader.loadAsScene = function (file, owner, parentSize) {    var node = cc.BuilderReader.load(file, owner, parentSize);    var scene = cc.Scene.create();    scene.addChild(node);    return scene;};cc.BuilderReader.loadAsSceneFrom = function (path, ccbName) {    cc.BuilderReader.setResourcePath(path + "/");    return cc.BuilderReader.loadAsScene(path + "/" + ccbName);}cc.BuilderReader.loadAsNodeFrom = function (path, ccbName, owner) {    cc.BuilderReader.setResourcePath(path + "/");    return cc.BuilderReader.load(path + "/" + ccbName, owner);}cc.BuilderReader.runScene = function (module, name) {    var director = cc.Director.getInstance();    var scene = cc.BuilderReader.loadAsSceneFrom(module, name);    var runningScene = director.getRunningScene();    if (runningScene === null) {        cc.log("runWithScene");        director.runWithScene(scene);    }    else {        cc.log("replaceScene");        director.replaceScene(scene);    }}var ccb_resources = [    {type: 'image', src: "Resources/HelloWorld.png"},    {type: 'image', src: "Resources/CloseNormal.png"},    {type: 'image', src: "Resources/CloseSelected.png"}];require("MainLayer.js");require("StartLayer.js");if (sys.platform == 'browser') {    var Cocos2dXApplication = cc.Application.extend({        config: document['ccConfig'],        ctor: function () {            this._super();            cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];            cc.initDebugSetting();            cc.setup(this.config['tag']);            cc.AppController.shareAppController().didFinishLaunchingWithOptions();        },        applicationDidFinishLaunching: function () {            var director = cc.Director.getInstance();            // director->enableRetinaDisplay(true);            // director.setDisplayStats(this.config['showFPS']);            // set FPS. the default value is 1.0/60 if you don't call this            director.setAnimationInterval(1.0 / this.config['frameRate']);            var glView = director.getOpenGLView();            glView.setDesignResolutionSize(1280, 720, cc.RESOLUTION_POLICY.SHOW_ALL);            cc.Loader.preload(ccb_resources, function () {                cc.BuilderReader.runScene("", "StartLayer");            }, this);            return true;        }    });    var myApp = new Cocos2dXApplication();} else {    cc.BuilderReader.runScene("", "StartLayer");}

Everything is ready. Click Run to see the effect as follows. First, enter the start interface and click play to jump to the main game interface.



: Http://www.kuaipan.cn/file/id_25348935635744469.htm? Source = 1


In the next article, I will introduce the font design of cocos2d-x editor)

Source: cocos2d-x editor







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.