Legomite Posted August 12, 2014 Share Posted August 12, 2014 How exactly do you make a movable sprite? I think I know the events but isn't there like a speed or velocity? Do you have to make a class or something? This is a bit hard to learn since there is no simple tutorial like on codecademy. Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted August 13, 2014 Share Posted August 13, 2014 Do you mean a moveable physics player, or just a moveable sprite? Quote Link to comment Share on other sites More sharing options...
PixelPicoSean Posted August 13, 2014 Share Posted August 13, 2014 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)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.