问题
I'm developing a basic game for IOS using SpriteKit. iPhone devices come in many shapes and colours. The former of which is giving me a bit of a headache. Different sized screens.
This is a two part question. Firstly
What solutions have other people implemented to achieve a uniform layout over multiple display sizes?
The current solution I'm looking at adopting is to find the device type as suggested in one of the solutions here Scale sprite kit game for all devices, I'll be implementing this through using Alessandro Ornano solution to the problem How to determine the current iPhone/device model?. Then changing the size and the position of game objects depending on device type.
Secondly:
Is it possible to have a function/method run only on application installation. Do apple allow this. If so where would I make the call to the method?
回答1:
1) This is 100% dependent on the actual game. You need to ask yourself what do you expect the experience to be for your user.
Sometimes, you can get away with showing more of the game. In this case, you develop with a square aspect ratio in mind.
Sometimes, you can get away with showing more from the top. In this case, you develop your game using the longest aspect ratio (iPhone X), but keeping your playable are in your shortest aspect ratio (iPad).
Sometimes, you need for everybody to have the same experience. In this case, you make your playable area the shortest aspect ratio, and you provide a fancy border around the playable area.
There is no need to detect what phone you are using. This is actually a bad approach when developing because you only focus on today, not tomorrow. A lot of people are kicking themselves when the X came out because they had to go in and update their app to accommodate it for the X.
2)Use the App Delegate
来源:https://stackoverflow.com/questions/58040836/xcode-spritekit-game-how-to-configure-the-ui-for-multiple-screen-sizes-during