Jump to content

Sprite.body.setSize(width, height); not working properly


ZoomBox
 Share

Recommended Posts

Hello (it's me again) !

 

I have a problem with Sprite.body.setSize(width, height);

Let me show you my extend Sprite:

Brick=function(_state, _x, _y,){    Phaser.Sprite.call(this, _state.game, _x, _y);    this.game.physics.enable(this, Phaser.Physics.ARCADE);    this.loadTexture("brick");    this.game.add.existing(this);};Brick.prototype = Object.create(Phaser.Sprite.prototype);Brick.prototype.constructor = Brick;Brick.prototype.setDimensions=function(_width, _height){    this.width=_width;    this.height=_height;    this.body.setSize(_width,_height);}

It's very basic here (I simplified) but when I call my Brick.setDimention(_width, _height), this sprite itself is correctly sized but the body is smaller.

 

Check this screen:

post-7992-0-02080100-1405519750.png

 

I'm not used to arcade physics and it's very strange.

Thank you in advance.

 

Link to comment
Share on other sites

Edit (we posted at the same time): This is the latest Phaser (2.0.6) and the sprite wasn't resized anywhere else.

 

Thank you lewster32 for the time you often offer me.

 

I found a solution but not the problem: I was loading the texture AFTER enabling Physics.

By enabling the physics after, I'm abe to resize the entire thing without using Sprite.body.setSize(a, B);, setting the Sprite.width and Sprite.height is enought.

 

So here it is:

Brick=function(_state, _x, _y,){    Phaser.Sprite.call(this, _state.game, _x, _y);    this.loadTexture("brick");    this.game.physics.enable(this, Phaser.Physics.ARCADE);    this.game.add.existing(this);};Brick.prototype = Object.create(Phaser.Sprite.prototype);Brick.prototype.constructor = Brick;Brick.prototype.setDimensions=function(_width, _height){    this.width=_width;    this.height=_height;}

It doesn't explains why setSize() doesn't work properly, but... I suppose you're not allowed to create a physic body before setting a texture.

 

 

Thank you again !

Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...

I've noticed that "this.player.anchor.setTo(0.5);" will create a bounding box centered on the player.body in Phaser v2.2.2 when "this.game.debug.body(this.player);" is used,

but in the latest Phaser v2.6.2, "this.game.debug.body(this.player);" shows a bounding box anchored at top left even if "this.player.anchor.setTo(0.5);" is previously applied.

Was this an intentional change or a bug in the new version?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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