I'm new to game development and SpriteKit too, working on small game with it. Unfortunately I cannot present SKSpriteNode
properly on both devices - 3,5 inch and 4 inch.
I have a bit of experience with Cocos2d, and all that positioning stuff was made inside SpriteBuilder tool which is very handy. In SpriteKit it should be done programmatically.. the problem is that scale of a node differs on the devices, take a look:
Here the code of positioning in MyScene.m:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
_screenRect = [[UIScreen mainScreen] bounds];
_screenHeight = _screenRect.size.height;
_screenWidth = _screenRect.size.width;
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background"];
[background setPosition:CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))];
[self addChild:background];
_grid = [[DVGrid alloc] initGrid];
[_grid setScale:0.65f];
[_grid setAnchorPoint:CGPointMake(0.0f, 0.5f)];
[_grid setPosition:CGPointMake(10.0f, _screenHeight/2)];
[self addChild:_grid];
}
return self;
}
and init of DVGrid.m which is subclass of SKSpriteNode:
- (instancetype)initGrid {
self = [super initWithImageNamed:@"grid"];
if (self) {
[self setUserInteractionEnabled:YES];
}
return self;
}
What is wrong here?
Go all the way back to where you created your scene. It looks like you might have your scene's scaleMode set to aspect fill, which could cause this behavior if you're designing for 3.5 and then upscaling.
[scene setScaleMode:SKSceneScaleModeAspectFill];
I'd suggest switching to a different scale mode, like SKSceneScaleModeResizeFill
, which should produce the desired results.