SKSpriteNode bring image to bottom - IOS game

87 Views Asked by At

i am new to ios development. i am learning to develop a game using this youtube tutorial.

I want the ground image to be on the bottom of the screen. I can manually give some values and bring it to bottom. But i want it to detect the frame size and get the values for X and Y.

Currently it looks like this.

enter image description here

import SpriteKit
import GameplayKit

class GameScene: SKScene {

    var Ground = SKSpriteNode()



    override func didMove(to view: SKView) {


        Ground = SKSpriteNode(imageNamed: "Ground")
        Ground.setScale(0.5)
        Ground.position = CGPoint(x:self.frame.width/2, y: 0 + Ground.frame.height/2)
        self.addChild(Ground)

    }



    override func update(_ currentTime: TimeInterval) {
        // Called before each frame is rendered
    }
}

can some one help me to bring the ground image to bottom.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use minX, minY, midX, midY, maxX and maxY of a CGRect to get the actual values of those positions.

So in your case you could write:

Ground.position = CGPoint(x:self.frame.midX, y: self.frame.maxY)

and your ground image should be...grounded...(sorry :))

Hope that helps you.