Jump to content

Tilemap render bounds don't update when changing game size


Eendhoorn
 Share

Recommended Posts

I'm trying to make game resize appropriately to size of the window/screen.
Everything's working out great, except for the tilemap. It seems like the rendering bounds are not updated.

(typescript)

  onResize() {

            this.game.scale.refresh();

            var newWidth = window.innerWidth / 3;
            var newHeight = window.innerHeight / 3;

            this.game.scale.setGameSize(newWidth, newHeight);
            this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; //need to call this to apply new size?
            this.game.camera.setSize(newWidth, newHeight);

            for (var i = 0; i < this.tilemap.layer.length; i++) {
                this.tilemap.layer[i].width = newWidth;
                this.tilemap.layer[i].resizeFrame(this.tilemap, newWidth, newHeight);
                this.tilemap.layer[i].crop(new Phaser.Rectangle(0, 0, newWidth, newHeight), false);
                this.tilemap.layer[i].updateCrop();
            }
            
            this.game.camera.follow(this.player.sprite, Phaser.Camera.FOLLOW_TOPDOWN, 0.8, 0.8);
        }

tilemap_bounds.gif.3a918deea3ba7f0a52faa56f950559bb.gif
As you can see I've tried everything, I would've expected resizeFrame or crop to do something, but unfortunately they don't.
Do note that the rest of the game updates the size correctly, as the fish get rendered in the widened area just fine.

Any ideas how to update the tilemap to the new size?

Thanks!

Link to comment
Share on other sites

  • 2 months later...

Thanks samme.

Here's a small snippet so we don't have to use keep putting in the variable names of every layer we add.

 

		game.world.children.forEach(obj => {
			if(obj.type == 10) obj.resize(x, y) // If a tilemap layer, resize it...
		})

 

i just stuck there on my electron "resize" event listener

although, i got stuck cause i thought game.scale.setGameSize would take into account TilemapLayers lol

Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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