Jump to content

how does setBounds work?


grumpygamer
 Share

Recommended Posts

I've read the documentation that says:

 

 

Updates the size of this world and sets World.x/y to the given values The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds.

 

So for example if I have a 320 x 200 canvas and want to extend that to 480 x 380 (random numbers here) I would do:

game.world.setBounds(0,0,480,380);

BUT would that yield this result

post-13934-0-66008400-1435047141.jpg

 

or this result

post-13934-0-28087400-1435047141.jpg

 

Would I have to give negative margins if it presently outputs result 1?

 

Thanks

Link to comment
Share on other sites

I still can't understand centering.
If I add let's say 100px on the left and right of the screen like this:

var game = this.game;    bound_margin = 100;    newLeft = this.game.world.bounds.left-bound_margin;    newRight = this.game.world.bounds.right+bound_margin;    game.world.setBounds(newLeft, 0, newRight, window.innerHeight);    // THIS MUGHT BE WRONG    bg = game.add.tileSprite(newLeft, 0, newRight, window.innerHeight, 'background');

and then add some camera panning like so: 

update: function() {    if (cursors.left.isDown) {        this.game.camera.x -= bound_margin;    }    if (cursors.right.isDown) {        this.game.camera.x += bound_margin;    }}

the camera only moves to one side!

 

Edit:-----------------------------------------------

 

Also what I don't understand is why even with the new bounds in place the ship drawing point still remains at the top left of the window.

It should be out of the window?

Edited by grumpygamer
Link to comment
Share on other sites

Ok, I've just understood by myself.

 

There is no particular need to set negative boundaries UNLESS you want to then calculate a 0-based area.

 

You only need to create the new bounds starting at 0,0, make them as big as you like, THEN center the camera.

Job done.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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