Cocos2D-JS-Quick-Tutorials
Cocos2D-JS-Quick-Tutorials copied to clipboard
04 | Cocos2D-JS | How to center a sprite in Screen
04 | How to center a sprite in Screen
Game.layers.js
In the Game.layers.js a) Take the dimensions of the canvas b) Define the positions x and y c) Define the value of the anchor
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(); //a
var sprite = new cc.Sprite ( "HelloWorld.png" );
sprite.attr({
x: size.width / 2, //b
y: size.height / 2,
anchorX: 0.5, //c
anchorY: 0.5
});
game.addChild(sprite);
};