06 | Cocos2D-JS | How to Move a Sprite on the Screen
Opened this issue · 0 comments
Gurigraphics commented
06 | How to Move a Sprite on the Screen
Game.layers.js
In the Game.layers.js
a) set the time of movement
b) set the horizontal distance of the movement
c) set the vertical distance of the movement
d) set the motion action
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 sprite = new cc.Sprite ( "HelloWorld.png" ) ;
sprite.attr({
x: size.width / 2,
y: size.height / 2,
anchorX: 0.5,
anchorY: 0.5,
time: 2, //a
moveX: 100, //b
moveY: 150 //c
});
game.addChild(sprite);
sprite.runAction( new cc.MoveBy( sprite.time, cc.p( sprite.moveX, sprite.moveY ) )); //d
};