I’m building a board game with Phaser and it has two cameras, one for the menu and one for the board. I’d like for the board camera to zoom when the window is resized so that the board fills the camera, and I have it zoomed correctly but the problem now is that the board needs to be repositioned and I can’t figure out the math for determining the coordinates. Here’s a clipped version of the resize function:
The menu is the grey block on the left, and the idea is that when the window gets resized, the board should be flush with the menu as well as the edges of the window. The board might end up being a bit small on phones so the user will need to be able to zoom and drag
To me, what you’re trying to do in the code seems a little complicated. Is there a reason why you can’t make one scene for the game and one scene for the menu (with a fixed camera) and then overlay the menu? With semi-transparency on the menu, that would allow you to keep the game board centered at all times, plus you can just have a larger menu. Depending on how complex your game becomes, having the code all in this one class will become a nightmare. Better to split concerns IMO.
Also, I don’t know if this was just for your example, but try putting your styles in CSS instead of JavaScript and put your game in a div instead of the body. That would give you flexibility if you ever need to add something to the webpage outside of the game.
I would size boardCamera to its available size on the game canvas (not boardArea), then you can use centerOn() to scroll to the center of the board container.