Last active
November 15, 2018 11:09
-
-
Save menangen/d5c00a78d0a77d2f3f220954f6262cff to your computer and use it in GitHub Desktop.
SpriteKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SpriteKit | |
import GameplayKit | |
class GameScene: SKScene { | |
override func didMove(to view: SKView) { | |
let frequency: Double = 1.0 | |
let sampleCount: Int32 = 16 | |
let mapSize: Double = 5 | |
let noiseSource = GKRidgedNoiseSource( | |
frequency: frequency, | |
octaveCount: 3, | |
lacunarity: 2.7, | |
seed: 0) | |
let noise = GKNoise(noiseSource) | |
noise.gradientColors = [ | |
-1.0 as NSNumber : NSColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0), | |
1.0 as NSNumber : NSColor(red: 0.5, green: 0.5, blue: 0.9, alpha: 1.0) | |
] | |
var noiseMap = GKNoiseMap(noise, | |
size: double2(mapSize,mapSize), | |
origin: double2(0.0, 0.0), | |
sampleCount: int2(sampleCount,sampleCount), | |
seamless: false) | |
var noiseTexture = SKTexture(noiseMap: noiseMap) | |
var spriteNode = SKSpriteNode(texture: noiseTexture, size: CGSize(width: 256, height: 256)) | |
spriteNode.position = CGPoint(x: frame.midX, y: frame.midY) | |
addChild(spriteNode) | |
noiseMap = GKNoiseMap(noise, | |
size: double2(mapSize,mapSize), | |
origin: double2(21.0, 0.0), | |
sampleCount: int2(sampleCount,sampleCount), | |
seamless: false) | |
noiseTexture = SKTexture(noiseMap: noiseMap) | |
spriteNode = SKSpriteNode(texture: noiseTexture, size: CGSize(width: 256, height: 256)) | |
spriteNode.position = CGPoint(x: frame.midX + 256, y: frame.midY) | |
addChild(spriteNode) | |
} | |
override func mouseDown(with event: NSEvent) { | |
} | |
override func update(_ currentTime: TimeInterval) { | |
// Called before each frame is rendered | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SpriteKit | |
import GameplayKit | |
class ViewController: NSViewController { | |
@IBOutlet var skView: SKView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
if let view = self.skView { | |
// Load the SKScene from 'GameScene.sks' | |
let scene = GameScene() | |
// Set the scale mode to scale to fit the window | |
scene.scaleMode = .resizeFill | |
scene.size = view.bounds.size | |
// Present the scene | |
view.presentScene(scene) | |
view.ignoresSiblingOrder = true | |
view.preferredFramesPerSecond = 1 | |
view.showsFPS = true | |
view.showsNodeCount = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment