Reputation: 3718
I have an image [email protected] it's dimensions 1240 x 1240 pixels or 620 x 620 points. I want to use it for all iPhone models (different screen sizes). All I want it to resize it, but I can't figure out how to do this properly.
Here is what's go wrong:
let sprite = SKSpriteNode(imageNamed:"mySprite")
sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
println(sprite.size)
sprite.size = CGSize(width: 300, height: 300)
println(sprite.size)
println(self.view?.frame.size)
self.addChild(sprite)
Here is log from testing on the iPhone 4S:
(620.0,620.0)
(300.0,300.0)
Optional((480.0,320.0))
log looks ok, but on screen I can see that image is bigger than iPhone 4S width. It's width and height (it's a square) almost as high as iPhone 4 screen height (about 440 pts).
Scene scaleMode is AspectFill
.
Scene and sprite xScale
and yScale
= 1.0
I don't understand what I'm doing wrong.
Upvotes: 2
Views: 2506
Reputation: 1098
Based on the log message from your view's frame, the width is 480 and the height is 320, meaning your view is in landscape mode.
If your SKScene's size is set to the size of your view in portrait mode, using scaleMode AspectFill
will stretch the width of your scene from 320 to 480.
This means your SKSpriteNode will seem 450pts instead of 300pts.
You probably want to use SKSceneScaleModeResizeFill
instead?
Upvotes: 1