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

Change Camera Rect


cheapdevotion
 Share

Recommended Posts

Hey Guys,

Coming from Unity, to zoom the camera on a scene I could simply change the orthographic size, but some of the simple practices are lost on me with Phaser.

 

What I am trying to do is load a tilemap, but actually set the camera rect to be a small portion of the screen. Once the camera rect is set, I would like to scale the screen to fit the browser window, so I essentially zoom into a certain part of the tilemap.

 

issue.png

 

I have tried setting the game.camera.width and game.camera.height. I have also tried using the game.camera.setSize() and they don't seem to have an effect. What am I doing wrong?

 

Here is what my code looks like:

 

(function () {var game = new Phaser.Game(640, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() {   game.load.tilemap('map', 'assets/tileset1.png', 'assets/map.json', null, Phaser.Tilemap.JSON);   game.stage.scaleMode = Phaser.StageScaleMode.EXACT_FIT;    game.stage.scale.refresh();}var map;function create() {   map = game.add.tilemap(0, 0, 'map');   game.camera.width = 320;   game.camera.height = 200;}})();

 

Link to comment
Share on other sites

You're not doing anything wrong, you just can't change the camera dimensions - they match the game size at the moment. What you could try doing though is scaling either the tilemap or the Stage on which everything lives. The tilemap is rendered into a container which can be scaled up/down. I expect this will blow out the tile collision though, but still might be worth trying.

Link to comment
Share on other sites

  • 1 month later...

 

 

You're not doing anything wrong, you just can't change the camera dimensions - they match the game size at the moment. What you could try doing though is scaling either the tilemap or the Stage on which everything lives. The tilemap is rendered into a container which can be scaled up/down. I expect this will blow out the tile collision though, but still might be worth trying.

 

I am trying to do something similar to this...

 

In this example, how would you scale the Stage in which everything lives?

 

Thanks for your help!

Link to comment
Share on other sites

  • 1 year later...

You're not doing anything wrong, you just can't change the camera dimensions - they match the game size at the moment. What you could try doing though is scaling either the tilemap or the Stage on which everything lives. The tilemap is rendered into a container which can be scaled up/down. I expect this will blow out the tile collision though, but still might be worth trying.

I don't quite understand. If you can't change the camera dimensions, what is the point of the setSize method and height/width properties?

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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