Sign in to follow this  
Eendhoorn

Tilemap render bounds don't update when changing game size

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hey @samme;

Just a question: here you're using Layer.resize alone; but have you ever used it in conjunction with the code you're using here? :


I tried it and having the scale manager set as RESIZE makes the zoom code scale the whole of the game window inside the window.
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.