Jump to content

[Phaser 2.0.1] Arcade physics overlap with a scaled sprite


goshki
 Share

Recommended Posts

Hi,

 

I have a sprite that gets scaled up x4 during the game but is then reverted to scale x1. Despite of scaling it down to x1 the game.physics.arcade.overlap() reports overlaps as if the sprite was still at x4 scale.

 

To scale the sprite back to x1, I use:

sprite.scale.setTo(1, 1);

Is this a bug or do I do something wrong?

 

Link to comment
Share on other sites

 

You using the final release 2.0.1? (that came out yesterday)

 

There's nothing wrong with how you've scaled the sprite.

 

Stick a debug on the body maybe?

game.debug.body(sprite);

 

Yes, I'm using Phaser 2.0.1. I've also tried using debug draw and the bounds are rendered properly.

Link to comment
Share on other sites

I'm getting problems with sprite scaling as well... Problems that did not exist in older versions (prior to 2.0).

 

Create a sprite like so:

var s = game.add.sprite(x,y,"mysprite");s.scale.setTo(2,2);

... the above works and does what the Phaser example does (the example called "Scale A Sprite") which also works.

 

However, there are issues if you scale it when the sprite has a non-default anchor and is part of the ARCADE physics:

game.physics.startSystem(Phaser.Physics.ARCADE);var s = game.add.sprite(x,y,"mysprite");game.physics.enable(s, Phaser.Physics.ARCADE);s.anchor.setTo(0.5,0.5);s.scale.setTo(2,2);

Apart from the above, I've tried and succeeded in showing a problem with scale just by modifying the "Scale A Sprite" Phaser example by adding the physics engine and anchor and sprite scaling. Unless I'm insane that is!

Link to comment
Share on other sites

I wonder what I could be doing wrong... I just tried going to a different computer and doing a git clone of phaser-examples:

 

git clone https://github.com/photonstorm/phaser-examples.git

 

then running the example for scale a sprite. Confirmed that it worked. Then modified it by starting the ARCADE system and enabling it for the sprite in the example and setting the scale of the sprite to something other than 1,1.  I see different behaviour depending on if I do a sprite.scale.setTo(2,2) or .setTo(1,2) for example. The .setTo(1,2) causes the sprites to all move up whereas the .setTo(2,2) causes the sprites to move up and to the left.  I will paste the exact code below... I wonder what is wrong?  At the top of the example page it shows that it is using Phaser Version: 2.0.2

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create});function preload() {    game.load.image('disk', 'assets/sprites/darkwing_crazy.png');}function create() {    game.physics.startSystem(Phaser.Physics.ARCADE);    for (var i = 0; i < 15; i++)    {        //  Create 15 sprites at random x/y locations        var sprite = game.add.sprite(game.world.randomX, game.world.randomY, 'disk');        //  Pick a random number between -2 and 6        var rand = game.rnd.realInRange(-2, 6);        //  Set the scale of the sprite to the random value        game.physics.enable(sprite,Phaser.Physics.ARCADE);        sprite.anchor.setTo(0.5,0.5);        sprite.scale.setTo(1, 2);        //  You can also scale sprites like this:        //  sprite.scale.x = value;        //  sprite.scale.y = value;    }    }
Link to comment
Share on other sites

I just pasted all the code above into a new example and ran it and I just get lots of ducks all over the screen stretched in scale, no movement (which was a 2.0.1 bug, but fixed in 2.0.2).

 

In your DevTools console does it definitely say 2.0.2 in there? (I think the version in the examples repo is still 2.0.1 actually, best copy it over from the main phaser repo to be 100% sure).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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