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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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