how to properly remove nodes once outside of scene
So I finally found the solution. For some reason, Xcode doesn't like this code:
arrow.run(
SKAction.moveBy(x: 0.0 , y: -size.height - arrow.size.height, duration: TimeInterval(random(min: 2, max: 2))))
self.enumerateChildNodes(withName: "Arrow") { (node:SKNode, nil) in
if node.position.y < -500 || node.position.y > self.size.height + 550 {
node.removeFromParent()
}
}
I instead used the following code in place of this and the nodes were fixed, although they don't fully go off the screen, there isn't some weird stoppage and pileup at the bottom of the scene.
let moveEnemy = SKAction.moveTo(y: -800, duration: 4.0)
let deleteEnemy= SKAction.removeFromParent()
let enemySequence = SKAction.sequence([moveEnemy, deleteEnemy])
enemy.run(enemySequence)
Sprite Kit Remove SKNode From Parent When Off Screen
https://stackoverflow.com/a/24195006/2494064
Here is a link to an answer that removes nodes that go off the top of the screen. You would just have to replicate this to cover the entire border and set all of the walls to have the same contactBitMask values.
Basically the logic is to remove the SKSpriteNodes when they contact physicsbodies that you have resting just outside the visible screen.
Determine when a SpriteNode is leaving the screen?
You can check the position of each node to determine if it is in the scene. You can then remove the nodes, accordingly.
override func update(currentTime: CFTimeInterval) {
// Loop over all nodes in the scene
self.enumerateChildNodesWithName("*") {
node, stop in
if (node is SKSpriteNode) {
let sprite = node as SKSpriteNode
// Check if the node is not in the scene
if (sprite.position.x < -sprite.size.width/2.0 || sprite.position.x > self.size.width+sprite.size.width/2.0
|| sprite.position.y < -sprite.size.height/2.0 || sprite.position.y > self.size.height+sprite.size.height/2.0) {
sprite.removeFromParent()
}
}
}
}
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
Apparently, there was a /Users/myusername/local
folder that contained a include
with node
and lib
with node
and node_modules
. How and why this was created instead of in my /usr/local
folder, I do not know.
Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.
EDIT:
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
which is the equivalent of (same as above)...
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
or (same as above) broken down...
To completely uninstall node + npm is to do the following:
- go to /usr/local/lib and delete any node and node_modules
- go to /usr/local/include and delete any node and node_modules directory
- if you installed with brew install node, then run brew uninstall node in your terminal
- check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
- go to /usr/local/bin and delete any node executable
You may also need to do:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Additionally, NVM modifies the PATH variable in $HOME/.bashrc
, which must be reverted manually.
Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.
Detect when node hits bottom of screen
I think the problem is at your if statement. It should be like this
if (self.metalCrate.position.y == SOMETHING || self.crate.position.y >= 568) {
NSLog(@"Game Over.");
}
You need to compare self.metalCrate.position.y to something, otherwise, as long as self.metalCrate.position.y is not nil, your if verification will always be true.
Related Topics
Stroke Width with a Scenekit Line Primitive Type
How to Create an Nsdecimal Without Using Nsnumber and Creating Autoreleased Objects
Get the Callers Phone Number from an Incoming Call on Iphone
Error Domain=Nsposixerrordomain Code=100 "Protocol Error"
How to Convert Xcode 32 Bit App into 64 Bit Xcode App
Default Value of Maxconcurrentoperationcount for Nsoperationqueue
Font Size on Universal Storyboard
How to Query Nearest Users in Firebase with Swift
Not Getting the Email Using Google Authentication in Firebase
How to Create the Current Date (Or Any Date) as an Nsdate Without Hours, Minutes and Seconds
Swiftui Won't Display Custom Font
Native Zlib Inflate/Deflate for Swift3 on iOS
Always Got Nil Value from the Function in iOS
How to Get the Scnview Camera Position When Using Allowscameracontrol
Multiple Unusernotifications Not Firing