UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Project 11 - Part 1

Forums > 100 Days of Swift

Hi everyone! I'm getting started with SpriteKit on Project 11. Couple issues I'm facing so far. First, is the background image does not automatically fill the entire screen like it does in Paul's video? Second, when creating the boxes/balls, they fall off the screen. In Paul's video, they stop at the bottom. I've copied the code identically so am not sure why I'm facing these problems.

This is my GameScene.swift file:

import SpriteKit

class GameScene: SKScene {
    override func didMove(to view: SKView) {
        let background = SKSpriteNode(imageNamed: "background")
        background.position = CGPoint(x: 512, y: 384)
        background.blendMode = .replace
        background.zPosition = -1
        addChild(background)

        physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard let touch = touches.first else { return }
        let location = touch.location(in: self)

        let ball = SKSpriteNode(imageNamed: "ballRed")
        ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.width)
        ball.physicsBody?.restitution = 0.4
        ball.position = location
        addChild(ball)
    }
}

This is what my background looks like: iPad Simulator Screenshot

3      

Ah. I was able to figure it out. On the GameScene.sks file, I hadn't adjusted my scene size to match that of Paul's. Once I set the width to 1024, and height to 768 it runs great!

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.