As you may know when using SpriteKit, applyImpulse
does not work well on all screens.
On an iPhone SE
, my ball moves extremely fast, but on the iPad Pro 2nd gen
the ball goes really slow.
Is there a way I can make this equal on all screens, in comparison to something like the width of the screen?
Say for example, I want my ball to move across the screen in 5 seconds on EVERY device, what formula would I use?
I have tested out the relation between screen sizes and time for my applyImpulse
to make the ball move to the edge of the screen:
Note: Points per second
is calculated by Half screen size
divided by Time to move
. The graph shows that the pixels per second
decreases with a bigger screen size.
How could I change my applyImpulse
to work on all screens? (not including making it specifically for every device, as I want this to be sustainable for the future)
If this is possible, please show a small swift
function, or if this cannot be done, please give me any suggestions (links to docs, forums, etc).
I appreciate any help by anyone.
EDIT: My GameViewController.swift
override for loading the scene:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Layout guides
guide = UIApplication.shared.keyWindow?.safeAreaInsets
if let view = self.view as! SKView? {
// Load scene
let scene = GameScene(size: view.frame.size)
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Set (0, 0) as the centre of the screen
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
view.showsPhysics = true
}
}