Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Tile Sprite.body.setRectangle change sprite's position


woratana
 Share

Recommended Posts

Hello,

 

I was stuck with this problem since yesterday.

 

When I create tile sprite, it worked fine:

this.ground = this.game.add.tileSprite(0, 750, 640, 206, 'ground');

the position is X: 0, Y: 750.

 

But when I tried to setRectangle to make it able to collide with other sprite, I added this code:

 

this.ground = this.game.add.tileSprite(0, 750, 640, 206, 'ground');this.ground.body.immovable = true;this.ground.body.setRectangle(640, 206, 0, 0);

The tile sprite somehow changed its position to the top of the screen. I have attach the image here.

 

Please let me know if there is anything I need to know about positioning and making tile sprite collidable.

post-5697-0-58287000-1392180930.png

Link to comment
Share on other sites

My solution has been to define the position of the sprite after using setRectangle. 

 

             this.game.add.sprite this.player = (200, 150, 'player'); 

             this.player.body.setRectangle (75, 160, 0, 0); 

             this.player.body.x = 200; 

             this.player.body.y = 150;

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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