Jump to content

Incorrect value after game.world.setBounds


Szbuli
 Share

Recommended Posts

Hello!

I modified the game bounds to be able to reduce the game area.

I used the following code in the Create method.

var x = -self.margin.left;
var y = -self.margin.top;
var w = game.world.width - (self.margin.left + self.margin.right);
var h = game.world.height - (self.margin.top + self.margin.bottom);
game.world.setBounds(x, y, w, h);

It works fine, but if i get the game.world.x value after one update cycle, the value changes to a positive value. For example first update cycle gives -245, after that 245.

Link to comment
Share on other sites

What are you trying to do? If you want your game to be a smaller size, why not make it a smaller size when making the Phaser.Game object?

Also, I'm not clear what changing the x and y of the world "mean", especially to make it smaller than the game. As far as I know the camera will be adjusted to match the new bounds so it'll still take up the whole game space?

Link to comment
Share on other sites

5 hours ago, Szbuli said:

I can't set the width and height of the camera, so i can't put margin. I still dont understand why i cant set a negative value to the world.x and world.y.

camera.bounds = new Phaser.Rectangle(-bounds_offset, -bounds_offset, (bounds_size+2*bounds_offset), (bounds_size+2*bounds_offset));

Easy peasy lemon squeezy

Link to comment
Share on other sites

1 hour ago, VitaZheltyakov said:

camera.bounds = new Phaser.Rectangle(-bounds_offset, -bounds_offset, (bounds_size+2*bounds_offset), (bounds_size+2*bounds_offset));

Easy peasy lemon squeezy

Still, the game width and height is the same as before. The docs said you cant change the size of it. 

Link to comment
Share on other sites

1 hour ago, drhayes said:

What are you trying to do? If you want your game to be a smaller size, why not make it a smaller size when making the Phaser.Game object?

Also, I'm not clear what changing the x and y of the world "mean", especially to make it smaller than the game. As far as I know the camera will be adjusted to match the new bounds so it'll still take up the whole game space?

I want to add a margin around the game but not always and some text may start from the margin area. 

Link to comment
Share on other sites

Maybe have a top-level group that you add most stuff to, then? That is positioned where you want it and allows for those margins?

Moving the World around should work, maybe, but it's tied into a lot of other stuff that your own group wouldn't be.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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