Jump to content

Object Velocity


0penS0urce
 Share

Recommended Posts

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

You have these two lines after your create and update definitions:

 

  1. platform.prototype = Object.create(Phaser.Sprite.prototype);
  2. 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

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...