Jump to content

Dynamic zoom bounds?


Babsobar
 Share

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
 

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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