Here's the problem: this board is not aligned to the screen- it falls off! Now, this is an easy fix. For example, one approach would be to simply move the main camera and align it by hand.
So far, I have been testing the game with a 6x6 grid layout. But what happens when I want to design a level with an 8x8 layout? Future me would wish I made it easier for myself. The alignment of the grid to the sceen space is not something that I want to think about, or make any team members think about throughout development.
Even with a 6x6 layout, if I were to align the board from the left bound of the screen at 16:9 ratio, it doesnt fit the screen. It is likely that some levels would need to be 8x8, too, so we need a way for the actual length of the board to adjust to the desired length, which is the length of the screen. The dimensions of the screen also change across devices with different aspect ratios, so by adding complications to the way the grid is aligned, we make it more adaptable in the long-run to different screen sizes.
In order to get from the actual length to the desired length, we need to divide the desired by the actual to get a multiplier. This multiplier denotes by how much the board has to be multiplied by in order for its length to become equivalent to the desired length.
After the board is generated with all the tiles and placeholder foxes we currently have, a function is called with the responsibility of aligning the board.
The use of the function produces these results:
From this, I can conclude that I have successfully provided a means from which the width of the board will be perfectly aligned with the width of the screen, which is not impacted by screen size differences between configurations, nor by the size of the grid in terms of how many tiles are present across the grid rows. This solution will be further applied to account for grid columns, which as you see in the second example is still in need of alignment (but not scaling). I will also have to align the board to the center rather than left.
These are the main changes made to align the width and height to the middle of the screen
This is the result of the changes made.
To summarise, width is scaled based on screen size (and is currently hard-coded to have a 5% margin for space on its sides) and is then aligned to the center.
As for the board height, there is no scaling to the screen as it is unlikely that, with the intended parameters supplied, there will be a lack of space for each animal element to fit on the screen across the grid height. The boards y position is aligned to the center of the screen, too.
As a final conclusion, screen size and grid layout sizes will now be very unlikely to cause visual problems in this game as the board manager script will handle the relevant alignment and scaling. While there could be even more considerations accounted for, the current configuration will very likely be sufficient for the future intentions of the project. It is also worth knowing that the positioning of the board manager game object must be at zeroed for proper function, but this is currently being ensured on the start function.
コメント