Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Created July 8, 2018 22:42
Show Gist options
  • Save topherPedersen/5132c9696b014ada1fed85a5c0a965f4 to your computer and use it in GitHub Desktop.
Save topherPedersen/5132c9696b014ada1fed85a5c0a965f4 to your computer and use it in GitHub Desktop.
App Team Lesson 1: Create New Sprite Kit Project, Replace Boilerplate Code, Add Background and Player Sprites
// This gist includes the two main files from a SpriteKit app for iOS and is for my personal reference
// teaching my app team students how to create 2D games for iOS using SpriteKit
//
// GameScene.swift
// HelloSpriteKit
//
// Created by Christopher Pedersen on 7/8/18.
// Copyright © 2018 Christopher Pedersen. All rights reserved.
//
import SpriteKit
class GameScene: SKScene {
let backgroundNode = SKSpriteNode(imageNamed: "BlankSuperMarioBackground")
let playerNode = SKSpriteNode(imageNamed: "MarioSprite")
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
backgroundNode.size.width = frame.size.width
backgroundNode.size.height = frame.size.height
backgroundNode.anchorPoint = CGPoint(x: 0.5, y: 0.0)
backgroundNode.position = CGPoint(x: size.width / 2.0, y: 0.0)
addChild(backgroundNode)
playerNode.position = CGPoint(x: size.width / 4.0, y: 82.0)
playerNode.size.width = playerNode.size.width / 8.0
playerNode.size.height = playerNode.size.height / 8.0
addChild(playerNode)
}
}
//
// GameViewController.swift
// HelloSpriteKit
//
// Created by Christopher Pedersen on 7/8/18.
// Copyright © 2018 Christopher Pedersen. All rights reserved.
//
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
var scene: GameScene!
override var prefersStatusBarHidden: Bool {
return true
}
override func viewDidLoad() {
super.viewDidLoad()
// 1. Configure the main view
let skView = view as! SKView
skView.showsFPS = true
// 2. Create and configure our game scene
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .aspectFill
// 3. Show the scene
skView.presentScene(scene)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment