Sign in to follow this  
Babsobar

Dynamic zoom bounds?

Recommended Posts

Hello everyone,
I'm looking to set some zoom bounds to the camera much like camera.setBounds sets bounds to the scrolling behavior of the camera to be when there are no more tiles.
I've searched the documentation and examples but there aren't any references to such a method or feature.

Thanks for any help
 

Share this post


Link to post
Share on other sites
13 hours ago, samme said:

// update()
var cam = this.cameras.main;

cam.setZoom(Phaser.Math.Clamp(cam.zoom, 0.2, 5));

 

This is good because it sets zoom min/max but it doesnt set that according to the maximum amount of map that can be revealed. What I'm looking for is something that sets the zoom's max to the maximum amount of tiles able to be shown so that the outside black of the map is never shown, or as little of it as possible is shown beofre it stop zooming

What I thought could be possible would be to create two variables, one containing the top left sprite of the map and the other containing the bottom right sprite and stop zooming if both are within camera bounds
That said, I can't find a way to check for wether or not a sprite is within camera bounds, in phaser 2 there was ' sprite.inCamera ' but I can't find it in phaser 3.

Share this post


Link to post
Share on other sites

Figured it out thanks to KingCosmic on the discord

For anyone wondering


create{

//Create two sprites, one for each diagonal corner

var topLeft = this.add.sprite(0,0)
var bottomRight this.add.sprite(mapWidth*32,mapHeight*32)

//add them both to an array

    testArray = []
    testArray.push(topLeft)
    testArray.push(bottomRight)
}

update{

//Test if they are both inside the camera view
cullTest = this.camera.main.cull(testArray)

if(cullTest.length == 2){
// restrict zoom or something else
}
}

In my case, this didn't work with getting the tiles, so I created two invisible sprites over each corner and test for those.

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.