How do I use SpriteKit for 2D games in Swift?

Learn how to use SpriteKit for developing 2D games in Swift. This guide covers the basics of setting up a SpriteKit project and creating simple game elements, providing a foundation for your game development journey.
SpriteKit, Swift, 2D games, game development, iOS games, SpriteKit tutorial

        // Import SpriteKit framework
        import SpriteKit

        class GameScene: SKScene {
            override func didMove(to view: SKView) {
                // Create a blue square
                let square = SKSpriteNode(color: .blue, size: CGSize(width: 100, height: 100))
                square.position = CGPoint(x: frame.midX, y: frame.midY)
                addChild(square)

                // Adding a label
                let label = SKLabelNode(text: "Hello, SpriteKit!")
                label.fontSize = 24
                label.position = CGPoint(x: frame.midX, y: frame.midY + 60)
                addChild(label)
            }
        }

        // Set up the view in AppDelegate or SceneDelegate
        let scene = GameScene(size: view.bounds.size)
        let skView = view as! SKView
        skView.presentScene(scene)
    

SpriteKit Swift 2D games game development iOS games SpriteKit tutorial