forked from Metrunui/TrumpeJump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCCloudGenerator.swift
More file actions
47 lines (38 loc) · 1.38 KB
/
SCCloudGenerator.swift
File metadata and controls
47 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// SCCloudGenerator.swift
// Nimble Ninja 2
//
// Created by Sam Coffey on 7/25/15.
// Copyright (c) 2015 coffey. All rights reserved.
//
import Foundation
import SpriteKit
class SCCloudGenerator: SKSpriteNode {
let CLOUD_WIDTH: CGFloat = 125.0
let CLOUD_HEIGHT: CGFloat = 55.0
var generationTimer: NSTimer!
func populate(num: Int) {
for var i = 0; i < num; i++ {
let cloud = SCCloud(size: CGSizeMake(CLOUD_WIDTH, CLOUD_HEIGHT))
let x = CGFloat(arc4random_uniform(UInt32(size.width))) - size.width/2
let y = CGFloat(arc4random_uniform(UInt32(size.height))) - size.height/2
cloud.position = CGPointMake(x, y)
cloud.zPosition = -1
addChild(cloud)
}
}
func startGeneratingWithSpawnTime(seconds: NSTimeInterval) {
generationTimer = NSTimer.scheduledTimerWithTimeInterval(seconds, target: self, selector: "generateCloud", userInfo: nil, repeats: true)
}
func stopGenerating() {
generationTimer.invalidate()
}
func generateCloud() {
let x = size.width/2 + CLOUD_WIDTH/2
let y = CGFloat(arc4random_uniform(UInt32(size.height))) - size.height/2
let cloud = SCCloud(size: CGSizeMake(CLOUD_WIDTH, CLOUD_HEIGHT))
cloud.position = CGPointMake(x, y)
cloud.zPosition = -1
addChild(cloud)
}
}