Cocos2D-JS-Quick-Tutorials
Cocos2D-JS-Quick-Tutorials copied to clipboard
03 | Cocos2D-JS | How to display a sprite on the screen
03 | How to display a sprite on the screen
Game.resources.js
In the Game.resources.js set the path to the image
Game.res = {
HelloWorld_png : "HelloWorld.png"
};
Game.g_resources = [];
for ( var i in Game.res ) {
Game.g_resources.push( Game.res[i] );
}
Game.layers.js
In the file Game.layers.js:
a) Create a new sprite b) Define the positions x and y c) Add the sprite to the game
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 sprite = new cc.Sprite ( "HelloWorld.png" ) ; // a
sprite.attr({ x: 0, y: 0 }); //b
game.addChild(sprite); //c
};