Skip to content

Instantly share code, notes, and snippets.

@alexpersian
Last active June 1, 2019 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpersian/4c2c48d6ae1bc42337a61d1dfa10a78e to your computer and use it in GitHub Desktop.
Save alexpersian/4c2c48d6ae1bc42337a61d1dfa10a78e to your computer and use it in GitHub Desktop.
// 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