Jump to content

Sprite does not stay fixed in Phaser


capitalmarkettools.org
 Share

Recommended Posts

I am running ubuntu 14.04 with Phaser (v2.3.0 "Tarabon" - Built: Thu Mar 26 2015 02:36:37).

I am trying to have two sprites where one of them (yellowRectangle) should be fixed and the other one (redSquare) moves towards the fixed sprite. The issue is that the sprite that should be fixed still moves when the two sprites collide.

I attempted the workaround to add

yellowRectangle.physicsType = Phaser.SPRITE;

but it does not help.

Here is the program

var game = new Phaser.Game(width="100", height="100", Phaser.AUTO,'pressIt', { preload: preload, create: create, update:update });

var redSquare; var yellowRectangle;

function preload() {
game.load.image('redSquare', '/redSquare25x25.png');
game.load.image('yellowRectangle', '/yellowRectangle100x10.png'); }

function create() {
game.physics.startSystem(Phaser.Physics.P2JS);

redSquare = game.add.sprite(x=game.world.centerX, y=35, 'redSquare');
game.physics.p2.enable(redSquare);

yellowRectangle = game.add.sprite(x=game.world.centerX, y=game.world.height - 100, 'yellowRectangle');
//was suggested to add due to bug in Phaser
//but does not fix it
//yellowRectangle.physicsType = Phaser.SPRITE;
game.physics.p2.enable(yellowRectangle);
yellowRectangle.body.moves = false;
yellowRectangle.immovable = true;
};


function update() {
redSquare.body.force.y = 500;
};

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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