Skip to content

Commit

Permalink
update tile animations
Browse files Browse the repository at this point in the history
- tile animations no longer driven by `SKAction`
    - changing `SKTilemap` speed will affect child layers
    - tile animations will respond to `SKTilemap` speed changes, and even run backwards
- add functions to alleviate tile seams, or "cracking"
- add `SKTiledSceneCamera.setCameraBounds(bounds:)`
  • Loading branch information
mfessenden committed Sep 15, 2017
1 parent 7e31db5 commit 4af8f98
Show file tree
Hide file tree
Showing 36 changed files with 829 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Resources/shaders/
Resources/test/
Resources/User/
docs/jazzy_output/
*.psd
*.html
Expand Down
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
Change Log
==========

1.16
-----

#### Changes

- add functions to alleviate tile seams, or "cracking"
- tile animations no longer driven by `SKAction`
- changing `SKTilemap` speed will affect child layers
- tile animations will respond to `SKTilemap` speed changes, and even run backwards
- add `SKTiledSceneCamera.setCameraBounds(bounds:)`
- add `SKTileset.getAnimatedTileData`
- add `SKTileset.renderTileData`
- add `SKTilesetData.frameAt(index:)`
- add `SKTilesetData.setTexture(_:forFrame:)`
- add `SKTilesetData.setDuration(interval:forFrame:)`
- remove `SKTile.pauseAnimation`


1.15
-----

#### Changes

- invert layer y-offsets properly
- add `DemoController` to manage scenes in iOS/macOS
- add `DemoController` to manage scenes in iOS/macOS demo targets


- add `SKTilemap.getLayer(atPath:)`
Expand Down
37 changes: 28 additions & 9 deletions Demo/DemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cocoa
/// Controller & Asset manager for the demos.
public class DemoController: NSObject, Loggable {

public var sceneCount: Int = 0
private let fm = FileManager.default
static let `default` = DemoController()

Expand Down Expand Up @@ -132,7 +133,7 @@ public class DemoController: NSObject, Loggable {

- parameter interval: `TimeInterval` transition duration.
*/
public func reloadScene(_ interval: TimeInterval=0.25) {
public func reloadScene(_ interval: TimeInterval=0.3) {
guard let currentURL = currentURL else { return }
loadScene(url: currentURL, usePreviousCamera: true, interval: interval, reload: true)
}
Expand All @@ -142,7 +143,7 @@ public class DemoController: NSObject, Loggable {

- parameter interval: `TimeInterval` transition duration.
*/
public func loadNextScene(_ interval: TimeInterval=0.25) {
public func loadNextScene(_ interval: TimeInterval=0.3) {
guard let currentURL = currentURL else { return }
var nextFilename = demourls.first!
if let index = demourls.index(of: currentURL), index + 1 < demourls.count {
Expand All @@ -156,7 +157,7 @@ public class DemoController: NSObject, Loggable {

- parameter interval: `TimeInterval` transition duration.
*/
public func loadPreviousScene(_ interval: TimeInterval=0.25) {
public func loadPreviousScene(_ interval: TimeInterval=0.3) {
guard let currentURL = currentURL else { return }
var nextFilename = demourls.last!
if let index = demourls.index(of: currentURL), index > 0, index - 1 < demourls.count {
Expand All @@ -172,19 +173,21 @@ public class DemoController: NSObject, Loggable {
- parameter usePreviousCamera: `Bool` transfer camera information.
- parameter interval: `TimeInterval` transition duration.
*/
internal func loadScene(url: URL, usePreviousCamera: Bool, interval: TimeInterval=0.25, reload: Bool = false) {
internal func loadScene(url: URL, usePreviousCamera: Bool, interval: TimeInterval=0.3, reload: Bool = false) {
guard let view = self.view else {
log("view is not set.", level: .error)
return
}

var hasCurrent = false
var liveMode = false
var liveMode = true
var showOverlay = true
var cameraPosition = CGPoint.zero
var cameraZoom: CGFloat = 1
var isPaused: Bool = false
var showObjects: Bool = false
var currentSpeed: CGFloat = 1
var sceneInfo: [String: Any] = [:]

if let currentScene = view.scene as? SKTiledDemoScene {
hasCurrent = true
Expand All @@ -202,6 +205,7 @@ public class DemoController: NSObject, Loggable {
}

isPaused = currentScene.isPaused
currentSpeed = currentScene.speed
}

// update the console
Expand All @@ -225,6 +229,7 @@ public class DemoController: NSObject, Loggable {
loggingLevel: self.loggingLevel, nil)

nextScene.liveMode = liveMode
sceneInfo["liveMode"] = liveMode

if (usePreviousCamera == true) {
nextScene.cameraNode?.showOverlay = showOverlay
Expand All @@ -241,8 +246,8 @@ public class DemoController: NSObject, Loggable {
tilemap.showObjects = (tilemap.boolForKey("showObjects") == true) ? true : showObjects
}

let sceneInfo = ["hasGraphs": (nextScene.graphs.isEmpty == false),
"hasObjects": nextScene.tilemap.getObjects().isEmpty == false]
sceneInfo["hasGraphs"] = (nextScene.graphs.isEmpty == false)
sceneInfo["hasObjects"] = nextScene.tilemap.getObjects().isEmpty == false

NotificationCenter.default.post(name: Notification.Name(rawValue: "updateUIControls"), object: nil, userInfo: sceneInfo)
nextScene.setupDemoLevel(fileNamed: url.relativePath)
Expand All @@ -252,12 +257,17 @@ public class DemoController: NSObject, Loggable {
nextScene.cameraNode.fitToView(newSize: view.bounds.size)
}

// TODO: find memory leak - commenting this out for iOS for now
// TODO: avoid memory spiking -> commenting this out for iOS for now
#if os(macOS)
self.demoQueue.async {
tilemap.defaultLayer.debugDrawOptions = self.debugDrawOptions
}
#endif

self.sceneCount += 1
// set the previous scene's speed
nextScene.speed = currentSpeed
NotificationCenter.default.post(name: Notification.Name(rawValue: "updateDelegateMenuItems"), object: nil, userInfo: sceneInfo)
}
}

Expand Down Expand Up @@ -286,6 +296,9 @@ public class DemoController: NSObject, Loggable {
if let tilemap = scene.tilemap {
updateCommandString("visualizing map bounds...", duration: 3)
tilemap.debugDrawOptions = (tilemap.debugDrawOptions.contains(.drawBounds)) ? tilemap.debugDrawOptions.subtracting([.drawBounds]) : tilemap.debugDrawOptions.insert([.drawBounds]).memberAfterInsert

let debugInfo: [String: Any] = ["mapGrid": tilemap.debugDrawOptions.contains(.drawGrid), "navGraph": tilemap.debugDrawOptions.contains(.drawGraph), "mapBounds": tilemap.debugDrawOptions.contains(.drawBounds)]
NotificationCenter.default.post(name: Notification.Name(rawValue: "updateDelegateMenuItems"), object: nil, userInfo: debugInfo)
}
}

Expand All @@ -299,6 +312,9 @@ public class DemoController: NSObject, Loggable {
if let tilemap = scene.tilemap {
updateCommandString("visualizing map grid...", duration: 3)
tilemap.debugDrawOptions = (tilemap.debugDrawOptions.contains(.drawGrid)) ? tilemap.debugDrawOptions.subtracting([.drawGrid]) : tilemap.debugDrawOptions.insert([.drawGrid]).memberAfterInsert

let debugInfo: [String: Any] = ["mapGrid": tilemap.debugDrawOptions.contains(.drawGrid), "navGraph": tilemap.debugDrawOptions.contains(.drawGraph), "mapBounds": tilemap.debugDrawOptions.contains(.drawBounds)]
NotificationCenter.default.post(name: Notification.Name(rawValue: "updateDelegateMenuItems"), object: nil, userInfo: debugInfo)
}
}

Expand All @@ -312,6 +328,9 @@ public class DemoController: NSObject, Loggable {
if let tilemap = scene.tilemap {
updateCommandString("visualizing map grid & bounds...", duration: 3)
tilemap.debugDrawOptions = (tilemap.debugDrawOptions.contains(.drawGrid)) ? tilemap.debugDrawOptions.subtracting([.drawGrid, .drawBounds]) : tilemap.debugDrawOptions.insert([.drawGrid, .drawBounds]).memberAfterInsert

let debugInfo: [String: Any] = ["mapGrid": tilemap.debugDrawOptions.contains(.drawGrid), "navGraph": tilemap.debugDrawOptions.contains(.drawGraph), "mapBounds": tilemap.debugDrawOptions.contains(.drawBounds)]
NotificationCenter.default.post(name: Notification.Name(rawValue: "updateDelegateMenuItems"), object: nil, userInfo: debugInfo)
}
}

Expand Down Expand Up @@ -405,7 +424,7 @@ public class DemoController: NSObject, Loggable {

/**
Send a command to the UI to update status.

- parameter command: `String` command string.
- parameter duration: `TimeInterval` how long the message should be displayed (0 is indefinite).
*/
Expand Down
Loading

0 comments on commit 4af8f98

Please sign in to comment.