-1

I've read that 0,0 is at the bottom left corner in Sprite Kit but when I position a sprite at that location nothing shows up on screen.

let squareSprite = SKSpriteNode(color: UIColor.purpleColor(), size: CGSize(width: 100, height: 100))
squareSprite.anchorPoint = CGPoint(x: 0, y: 0)                                  // bottom left corner of square
squareSprite.position = CGPoint(x: 0, y: 0)
addChild(squareSprite)

What am I missing?

Striving
  • 35
  • 8
  • 1
    possible duplicate of [Dealing with different iOS device resolutions in SpriteKit](http://stackoverflow.com/questions/25205882/dealing-with-different-ios-device-resolutions-in-spritekit) – Epic Byte Jul 12 '15 at 14:29

1 Answers1

0

This is probably happening because your view size, and your scene size have different dimensions. I guess you are using default game project template where the scene is loaded from .sks file (scene size in that case is 1024x768). If scene has different size than a view even if the sprite is added, it might not be visible because it can be off-screen. You can test this by adding a sprite at other position (eg. x=300,y=300). One thing you can do is to simply change scene's size (inside view controller) like this: scene.size = skView.bounds.size Also the important thing here is scene's scale mode (from the docs):

After a scene is rendered, its contents are copied into the presenting view. If the view and the scene are the same size, then the content can be directly copied into the view. If the two differ, then the scene is scaled to fit in the view. The scaleMode property determines how the content is scaled.

On top of this, I would suggest you to read this about how to initialize your scene in view controller and there is also debate about viewDidLoad vs viewWillLayoutSubviews methods.

Unrelated to your problem, but you might find useful to know that changing anchor point will not affect on physics body of a node. It's a purely visual property.

Hope this helps.

Community
  • 1
  • 1
Whirlwind
  • 14,286
  • 11
  • 68
  • 157