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

06 | Cocos2D-JS | How to Move a Sprite on the Screen #7

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

06 | Cocos2D-JS | How to Move a Sprite on the Screen #7

Gurigraphics opened this issue Apr 29, 2018 · 0 comments

Comments

@Gurigraphics
Copy link
Owner

Gurigraphics commented Apr 29, 2018

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
         
    }; 
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