Szbuli Posted May 23, 2016 Share Posted May 23, 2016 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 More sharing options...
Szbuli Posted May 24, 2016 Author Share Posted May 24, 2016 The problem in a phaser sandbox: http://phaser.io/sandbox/edit/uqJMeUdh The game.world.x value is logged into the console, from the update function. Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted May 24, 2016 Share Posted May 24, 2016 You are using the wrong approach. In this case, use camera boundary. Link to comment Share on other sites More sharing options...
Szbuli Posted May 25, 2016 Author Share Posted May 25, 2016 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. Link to comment Share on other sites More sharing options...
drhayes Posted May 25, 2016 Share Posted May 25, 2016 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 More sharing options...
VitaZheltyakov Posted May 25, 2016 Share Posted May 25, 2016 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 More sharing options...
Szbuli Posted May 25, 2016 Author Share Posted May 25, 2016 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 More sharing options...
Szbuli Posted May 25, 2016 Author Share Posted May 25, 2016 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 More sharing options...
VitaZheltyakov Posted May 25, 2016 Share Posted May 25, 2016 6 hours ago, Szbuli said: Still, the game width and height is the same as before. The docs said you cant change the size of it. If you would not have this effect, then what you want to do? Explain, please. Link to comment Share on other sites More sharing options...
drhayes Posted May 25, 2016 Share Posted May 25, 2016 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 More sharing options...
Recommended Posts