0

I’ve got a bit of a problem thats been befuddling me for quite some time. I’m developing a game for ios. Its almost finished and it works perfectly on my own iphone SE. However, running it on other screen sizes is causing me a headache. Its not so much a scaling issue, as the background scales fine. The issue is in fact a point scaling issue. The sprites appear at different locations on different devices. I’ve attached some photos so you can see what I mean. The weird looking one is on an iphone 8 and the good looking ones are on iphone SE. I’ve also included the code that defines where the sprites start from. Any help would be appreciated.Iphone se, iphone 8

As you can see above, everything has been shunted sideways for some reason. This is my problem.

   float branch1StartingPos = 284; //where the first branch starts so that it goes the length of the screen.
float branch2StartingPos = 856; //where the second branch starts so that it is completely off the screen and moves on until it gets to branch1startingpos in which case branch 1 completely on the screen.
float branchOffScreen = -284; //the position at which the branch is now completely off screen
float lifeForceStartingPos = 180.0; //where the green life force starts
Jobalisk
  • 728
  • 1
  • 6
  • 17
  • Screens simply have different sizes and aspect ratios, so you can't hardcode coordinates and expect the result to look appropriate on a range of devices. There are various approaches to solving the problem, but which to choose depends on the nature of the game. It's a common question; here's a recent SO thread: https://stackoverflow.com/questions/58040836/xcode-spritekit-game-how-to-configure-the-ui-for-multiple-screen-sizes-during – bg2b Mar 24 '20 at 16:11
  • @bg2b except that is the entire point of the creation of Sprite kit. You work in 1 virtual screen (your scene) and your view port determines how much you see (Your SKView) – Knight0fDragon Mar 24 '20 at 19:42
  • 'Weird" is relative. The first question I need answered before I can help you is how do you create your SKScene. Could you please show that. – Knight0fDragon Mar 24 '20 at 19:46
  • @Knight0fDragon Sure, but how to accommodate the different sizes and aspect ratios depends on the game. Whether that's showing a moving window on a fixed scene, letter boxing, clipping, nonuniform scaling, programmatically adjusting sizes and positions in the scene based on aspect ratio and/or size, or whatever will vary from game to game. I pointed to that thread as just a recent one that links to other threads that discuss some of the various options. – bg2b Mar 24 '20 at 21:04
  • @bg2b. Adjusting positions can vary per game, but you want to avoid it per device. Static is the way to go. Anything that is adjustable should be done via UI Kit, but as far as the actual game is concerned, you should design for 1 scene. Otherwise you end up creating different experiences (outside of viewing) across different devices. Best easy example to understand is pong. You do not want to develop pong with the paddles 10points away from the edges because that means your pong ball will be on a different field for each aspect ratio. – Knight0fDragon Mar 24 '20 at 21:10
  • @Knight0fDragon I think for some games having the playfield being different aspect ratios is fine. Others obviously only work with very strict and inflexible layouts. Pong I suspect would actually work fine with a range of aspect ratios if the ball is just bouncing off the side edges. You might tweak ball speed a bit depending on the aspect ratio so that the time to go from one paddle to the other is similar. The game doesn't have to play 100% identical on a phone vs on an iPad, just to be fun on both. Anyway, we're getting a bit mired in philosophical differences... – bg2b Mar 24 '20 at 21:26
  • @bg2b tweaking the ball speed is not enough, you have a more narrow playing fleld, meaning you would have to adjust the X speed without adjusting the Y speed, which means you would need your own physics engine. It goes beyond phone and pad, and is especially important when introducing score boards. You do not want your X players to have a gameplay advantage. almost every game engine development is designed the way sprite kit is. You do not want to be doing extra work to account for different aspect ratios, which is why you develop in a virtual screen style environment. – Knight0fDragon Mar 24 '20 at 21:32
  • @bg2b Basically design your game like a 3D game with a fixed camera on 1 plane. That may help you understand the virtual screen style environment better. – Knight0fDragon Mar 24 '20 at 21:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/210262/discussion-between-bg2b-and-knight0fdragon). – bg2b Mar 24 '20 at 21:39
  • Cheers for the comments, I had a feeling it had to do with me hard coding it. I’ll have a look at your linked thread. – Jobalisk Mar 26 '20 at 06:40

0 Answers0