[英]Sprite Kit - Notifier that a node is leaving the screen
Is there a event/notification in Sprite Kit that tells me when a node is leaving the screen? Sprite Kit中是否有事件/通知告诉我节点何时离开屏幕? Lets say I want a coloured circle to appear on top when it left the screen at the bottom. 让我们说当我离开屏幕底部时,我想要一个彩色圆圈出现在顶部。 Which means I need to know when it is leaving the screen. 这意味着我需要知道它何时离开屏幕。
You will need to check for yourself I think, 你需要自己检查我认为,
- (void)update:(NSTimeInterval)currentTime {
if (node.position.y > screenHeight+nodeSize){ // need to define first, of course
// do something like NSLog(); or [removeFromParent] or whatever =)
}
}
Sprite kit does not generate a notification when a sprite leaves screen. 当精灵离开屏幕时,精灵工具包不会生成通知。 You will need to add your own test. 您需要添加自己的测试。 Here's an example... 这是一个例子......
- (void) update:(NSTimerInterval)currentTime
{
CGPoint newPosition = CGPointMake(node.position.x, node.position.y);
if (node.position.y > maxY+node.size.y/2) {
newPosition.y = minY;
}
else if (node.position.y < minX-node.size.y/2) {
newPosition.y = maxY;
}
if (node.position.x > maxX+node.size.x/2) {
newPosition.x = minX;
}
else if (node.position.x < minX-node.size.x/2) {
newPosition.x = maxX;
}
node.position = newPosition;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.