Jump to content

Make a movable player?


Legomite
 Share

Recommended Posts

There're lots of ways to move a sprite, using tweens, adding physics body, move by set position directly... If you want to set a velocity you need to create a Body instance and sync sprite's position to that body.

var Ball = game.Class.extend({    init: function(x, y) {        // Sprite is the visible part        this.sprite = new game.Sprite('ball', x, y);        // And body is the physics part        this.body = new game.Body({            position: { x: x, y: y },            velocityLimit: { x: 100, y: 1000 },            collideAgainst: 0,            collisionGroup: 1        });        this.body.addShape(new game.Circle(32));        game.scene.world.addBody(this.body);    },    update: function() {        this.sprite.position.x = this.body.position.x;        this.sprite.position.y = this.body.position.y;    }});// Don't forget to add it to scene, so that the update method will be calledgame.scene.addObject(new Ball(128, 64));
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...