Jump to content

Sprite does not stay fixed in Phaser


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() {

redSquare = game.add.sprite(x=game.world.centerX, y=35, '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;
yellowRectangle.body.moves = false;
yellowRectangle.immovable = true;

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

Link to comment
Share on other sites


  • Recently Browsing   0 members

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