swift
swift

Reputation: 75

SKSpriteNode is gigantic

What am I doing wrong here?

let bgImage = SKSpriteNode(imageNamed: "Background.png")
var alloment1 = SKSpriteNode(imageNamed: "startingPatch.png")

override func didMoveToView(view: SKView) {
    bgImage.position = CGPointMake(CGRectGetMidY(self.frame), CGRectGetMidX(self.frame))
    self.addChild(bgImage)


    alloment1.position = CGPointMake(CGRectGetMidY(self.frame), CGRectGetMidX(self.frame))
    self.addChild(alloment1)
}

I have this set up in my GameScene.swift file. I have no clue what could be going on. My background png is 1920x1080px(which is the resolution for 6+) and the image I want to be on the screen is 180px

Edit:Image of what is happened!

Upvotes: 0

Views: 47

Answers (1)

Brennan Adler
Brennan Adler

Reputation: 915

Although the dimensions of the iPhone 6+ are 1920x1080px. XCode uses points instead of pixels for coding so that apps can be at least somewhat compatible with all of apples devices. The 6+ is 3X dense so in order to get the point density, divide the boundaries by 3(640 x 360).

All you have to do is scale each image down using the xScale and yScaleproperties like so.

let bgImage = SKSpriteNode(imageNamed: "Background.png")
var alloment1 = SKSpriteNode(imageNamed: "startingPatch.png")

override func didMoveToView(view: SKView) {
bgImage.position = CGPointMake(CGRectGetMidY(self.frame),     CGRectGetMidX(self.frame))
bgImage.xScale = 0.333
bgImage.yScale = 0.333
self.addChild(bgImage)



alloment1.position = CGPointMake(CGRectGetMidY(self.frame), CGRectGetMidX(self.frame))
alloment1.xScale = 0.333
alloment1.yScale = 0.333
self.addChild(alloment1)
}

Upvotes: 1

Related Questions