Last active
June 1, 2019 21:10
-
-
Save alexpersian/4c2c48d6ae1bc42337a61d1dfa10a78e to your computer and use it in GitHub Desktop.
This file contains 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
// Update is called once per frame | |
public override func update(_ currentTime: TimeInterval) { | |
// Collect a reference frame for the node's current position | |
let currentFrame = dvdNode.calculateAccumulatedFrame() | |
// Top bound | |
if currentFrame.maxY >= self.frame.maxY { | |
moveTransform.ty = -1.0 | |
dvdNode.run(changeColor) | |
} | |
// Right bound | |
if currentFrame.maxX >= self.frame.maxX { | |
moveTransform.tx = -1.0 | |
dvdNode.run(changeColor) | |
} | |
// Bottom bound | |
if currentFrame.minY <= self.frame.minY { | |
moveTransform.ty = 1.0 | |
dvdNode.run(changeColor) | |
} | |
// Left bound | |
if currentFrame.minX <= self.frame.minX { | |
moveTransform.tx = 1.0 | |
dvdNode.run(changeColor) | |
} | |
// Update the node's position by applying the transform | |
dvdNode.position = dvdNode.position.applying(moveTransform) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment