Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

00 | Cocos2D-JS | Game Start #1

Open
Gurigraphics opened this issue Apr 29, 2018 · 0 comments
Open

00 | Cocos2D-JS | Game Start #1

Gurigraphics opened this issue Apr 29, 2018 · 0 comments

Comments

@Gurigraphics
Copy link
Owner

Gurigraphics commented Apr 29, 2018

Welcome to Cocos2D-JS Quick Tutorials!

Start

  1. Download the project files -> link
  2. Export the zip folder.
    enter image description here

project.json

In this file we import the *.js files

{
    "debugMode"     : 1,
    "frameRate"     : 60,
    "id"            : "gameCanvas",
    "renderMode"    : 2,
    "jsList"        : [   
        "src/Game.vars.js",
        "src/Game.resources.js",
        "src/Game.layers.js",
        "src/Game.scenes.js"
    ]
} 

renderMode: 0 = auto
renderMode: 1 = canvas
renderMode: 2 = webGL

Game.resources.js

In this file we define the game resources.

Game.res = { 
    HelloWorld_png : "HelloWorld.png" 
};
	
Game.g_resources = []; 
    
for ( var i in Game.res ) {
    Game.g_resources.push( Game.res[i] ); 
}

Game.vars.js

In this file we declare the game variables

    Game = {}; 
    Game.scenes = []; 
    Game.scenes[1] = {}; 
    Game.layers = []; 
    Game.layers[1] = {}

Game.scenes.js

In this file we define the game scenes

    Game.scenes[1].extend = cc.Scene.extend({ 
    	onEnter:function () { 
    		this._super(); 
    		var layer = new Game.layers[1].extend(); 
    		layer.init(); 
    		this.addChild( layer ); 
    	} 
    });

Game.layers.js

In this file we define the game layers

    Game.layers[1].extend = cc.Layer.extend({ 
    	init: function () { 
    		this._super(); 
    		var game = this; 
    		Game.layers[1].start( game ); 
    	} 
    }); 
    Game.layers[1].start = function( game ){ 
    	var size = cc.director.getWinSize(); 
    	var label = cc.LabelTTF.create("Hello World", "Arial", 40);
    	label.setPosition(size.width / 2, size.height / 2);
    	game.addChild(label, 1); 
    };

Game.js

This file run the game and start the game scene

cc.game.onStart = function(){
    cc.LoaderScene.preload( Game.g_resources, function () {
        cc.director.runScene(new Game.scenes[1].extend());
    }, this);  
};  
  
window.onload = function(){  
	cc.game.run("gameCanvas");   
}

This project will display Hello World

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant