0penS0urce Posted June 14, 2015 Share Posted June 14, 2015 I'm trying to add velocity to one of my platforms, which is from an Object constructor since I'm trying to make an endless runner. But, I can never seem to get velocity on the platform, it only stay there. Am I missing an constructor, or do I put velocity in another function? By the way, if you have a better idea to make an endless runner, please share! Thanks in Advance!platform = function (game, x, y, vx){ Phaser.Sprite.call(this, game, x, y, 'plat'); this.anchor.setTo(0.5, 0.5); };platform.prototype.create = function(){}platform.prototype.update = function(){ this.x -= 20;}platform.prototype = Object.create(Phaser.Sprite.prototype);platform.prototype.constructor = platform;var game = new Phaser.Game(640, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() { game.load.image('plat', 'assets/platform.png');}function create() { plat1 = new platform(game, 350, 240, -1); game.add.existing(plat1); }function update() { } Link to comment Share on other sites More sharing options...
Skeptron Posted June 15, 2015 Share Posted June 15, 2015 Why not try to give it a real velocity? Like this.velocity.x = -20 or this.body.velocity.x = -20, can't remember which one. Also check that immovable = false. And when you have such a simple example, do not hesitate to make a Plunker (http://plnkr.co/), makes it way more easy for us to help you. Link to comment Share on other sites More sharing options...
drhayes Posted June 15, 2015 Share Posted June 15, 2015 You have these two lines after your create and update definitions: platform.prototype = Object.create(Phaser.Sprite.prototype); platform.prototype.constructor = platform; They will overwrite your custom update method with the sprite's prototype. As in, the "platform.prototype.update" goes away. Link to comment Share on other sites More sharing options...
Recommended Posts