Jump to content

Sprite created from BitMapData behaves strangely with P2 physics


Recommended Posts

I'm new to Phaser and just trying to setup a game with some basic elements, but already running into some problems. I setup a Sprite from BitMapData, a simple red circle. it shows fine, but as soon as I turn on Physics and enable them for the object, it just starts moving somewhat randomly. Gravity is off, there's nothing in my update loop, and I also tested with a Sprite created from an image and that one works fine. I'm assuming this is something silly that as a beginner I just don't know, am hoping somebody here will instantly know what I did wrong.

Here's the code for the Sprite:

var Player = function (game, x, y, color) {
    var bmd = game.add.bitmapData(256, 256);

    bmd.ctx.fillStyle = color;
    bmd.ctx.arc(x, y, 9, 0, Math.PI*2, true);

    Phaser.Sprite.call(this, game, x, y, bmd);

Player.prototype = Object.create(Phaser.Sprite.prototype);
Player.prototype.constructor = Player;

 * Automatically called by World.update
Player.prototype.update = function() {

module.exports = Player;


And here's the code for setting up the game:

var Player = require('../entities/player');

var Game = function () {


module.exports = Game;

Game.prototype = {

  create: function () {
    var me = this;

    // Set the background colour to blue
    me.game.stage.backgroundColor = '#00CC00';

    // Make sure the game keeps running even if user leaves browser
    me.game.stage.disableVisibilityChange = true;

    // Start the P2 Physics Engine

     // Set the gravity
    me.game.physics.p2.applyGravity = false;
    me.player = new Player(this.game, 200, 125, '#FF0000');


  update: function () {


  onInputDown: function () {


Link to comment
Share on other sites


  • Recently Browsing   0 members

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