4

Ok, so I've been trying to position a line on my iPhone 6s+ and my iPad 2. The line was added in an SKCamera (I don't know if that effects it or not). Here is the code for the line:

    var leftWall = SKSpriteNode()
    leftWall.size = CGSize(width: 1, height: 10000)
    leftWall.position = CGPoint(x: 0, y: 0)
    leftWall.color = UIColor.red
    leftWall.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: leftWall.size.width, height: leftWall.size.height))
    leftWall.physicsBody?.affectedByGravity = false
    leftWall.physicsBody?.isDynamic = false
    leftWall.physicsBody?.categoryBitMask = groundGroup
    leftWall.physicsBody?.collisionBitMask = ballGroup
    leftWall.physicsBody?.contactTestBitMask = 0
    theCamera.addChild(leftWall)

Okay, so the x position is 0,0 right? Here is how it looks on my iPhone 6s+:iPhone 6s+ As you see, the line is in the middle?

Here is how it looks on my iPad 2:

iPad 2

I just don't understand why the position of the line is completely different.. Please help me!

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Josh Schlabach
  • 401
  • 5
  • 17

1 Answers1

2

You are not taking into account the cropping that happens on the iPad, or your scaleMode is all wrong

What you need to do is set all nodes anchor points (Including the scene) to (0.5,0.5), make sure your GameScene has a static size and not based on view.frame (750,1334 is a good one) and that your scale mode is set to .aspectFill. This makes (0,0) the center of the screen, and you will notice everything line up on all devices

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44