1

ive just learning SpriteKit and Objective-C and i wonder why the origin of my view is out of the screen. I just created a default SpriteKit project within xCode 6 and simply just added an NSLog to show me the current location of the touch. The output on the console shows me, that this location is on 260.0 for the x-coodrinate and not near 0.0.

An Example that describes my problem within the scene implementation file: when i add a SKSpriteNode with a background image and position it on the origin of the screen with:

-(void)didMoveToView:(SKView *)view {
...
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Starfield"];
background.anchorPoint = CGPointZero;
background.position = CGPointZero;
[self addChild:background];
...
}

the picture is also out of the screen and not at the left bottom corner, where the anchorPoint was set.

I tried it in landscape mode, with all kinds of devices (iPhone4S,5,6,6+) and in pure portrait mode, but it also doesnt work. Thanks for help.

Greatings,

Martin

3 Answers3

2

In xcode 6.0.1 they use this new unarchiver which causes the problem. I had same problem as yours until i removed the unarchiver code and reverted back to how SKSCENES were created before the unarchiver which is this:

GameScene * scene = [GameScene sceneWithSize:skView.frame.size];

//instead of this 

GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];

After going back to the old way everything was working just fine. Hope this might help others.

1

Take a look at the scaleMode property, it is set in the GameViewController's viewDidLoad method. Here is documentation describing the different modes you can use. https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKScene_Ref/index.html#//apple_ref/c/tdef/SKSceneScaleMode

  • Thanks for the comment, this helps me a lot. By Default "SKSceneScaleModeAspectFill" was set and when i change it to "SKSceneScaleModeFill" the x and y coordinates match. But now the whole content is stretched. Is there a better solution to scale every Node down by hand? – Martin Haferanke Sep 24 '14 at 06:43
  • I'm currently researching a very similar problem. I found this link helpful http://blog.infinitecortex.com/2014/01/spritekit-understanding-skscene-scalemode/ You can also change the size of the scene. – jenndotcodes Sep 24 '14 at 16:13
  • 1
    Here is a great answer to a similar question http://stackoverflow.com/questions/25205882/dealing-with-different-ios-device-resolutions-in-spritekit – jenndotcodes Sep 24 '14 at 16:19
0

In your ViewController.m, change your scene's scale mode to SKSceneScaleModeAspectFill.

It should look something like this:

nameOfYourScene.scaleMode = SKSceneScaleModeAspectFill;

Hope that helps!

Alan Scarpa
  • 3,352
  • 4
  • 26
  • 48
  • Thanks for the comment, this helps me a lot. By Default "SKSceneScaleModeAspectFill" was set and when i change it to "SKSceneScaleModeFill" the x and y coordinates match. But now the whole content is stretched. Is there a better solution to scale every Node down by hand? – Martin Haferanke Sep 24 '14 at 06:44