Search code examples
iosswiftxcodesprite-kitskspritenode

How can I make an SKSpriteNode's velocity the same across different devices in SpriteKit?


My scene's size is view.bounds.size

I have a ball whose size is CGSize(width: frame.size.width/25, height: frame.size.width/25)

Originally, i had the ball speed at CGVector(dx: 25, dy: 25), but the ball went faster on smaller devices (SE) and slower on larger ones (8 Plus), which makes sense. So i changed the ball's x and y velocity to be frame.size.width * 0.067, which comes to 25 on an iPhone 7, which is the speed i like. Unfortunately, the ball still moved at different speeds on different devices. Then, I thought it must be that the ball has a different mass because the ball size is a percentage of the frame width. So i set the mass to be a constant, but still the ball moves at different speeds so now i have no idea whats going on.

Any ideas?


Solution

  • I think you can use constant size for scene (for playing area) and render that constant size to any screens with some transformation. Therefore all logic of your application will interact with constant size on any devices.
    If screen has other ratio, you can add decorative elements near edges of the screen.