Sprite kit SKSpriteNode在touchesEnded中从父级移除
当检测到SKSpriteNode上有触摸时,我在从其父节点删除该SKSpriteNode时遇到问题。代码如下:Sprite kit SKSpriteNode在touchesEnded中从父级移除,sprite-kit,touches,skspritenode,Sprite Kit,Touches,Skspritenode,当检测到SKSpriteNode上有触摸时,我在从其父节点删除该SKSpriteNode时遇到问题。代码如下: -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint sceneLocation = [touch locationInNode:self]; if ([_tableDoneButto
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint sceneLocation = [touch locationInNode:self];
if ([_tableDoneButton containsPoint:sceneLocation]) {
NSLog(@"here");
[self removeItemsFromView];
_headerNode.portLabel.text = [IPGameManager sharedGameData].world.player.port.name;
[_portNode show];
}
SKNode *nodeInPort = [_portNode nodeAtPoint:[touch locationInNode:_portNode]];
if ([nodeInPort.name isEqualToString:@"marketButton"]) {
[self showMarket];
}
}
}
在showMarket功能中,添加了一个“Done”SKSpriteNode
,以便用户可以在需要时离开市场。如上所述,如果\u tableDoneButton
包含触摸位置,它应该调用removietemsfromview
函数,该函数包含[\u tableDoneButton removeFromParent]代码>。以这种方式删除节点时,是否需要执行一些特殊操作
另一个问题:它似乎在1秒钟后被移除。运行[node removeFromParent]
时会发生什么情况?如果我在调用[self-removietemsfromview]
后将SKSpriteNode设置为nil,则工作正常。但我不应该这样做?试着调用[\u tableDoneButton removeFromParent]代码>此处直接代替[self removietemsfromview]代码>并查看是否有任何更改。您还可以尝试在-(void)touchsbegind:
中处理这些触摸。每当我调用removeFromParent
时,效果立即可见。另外:添加继续代码>在[\u portNode show]之后的行
以避免处理marketButton的相同触摸。调用[\u tableDoneButton removeFromParent]代码>直接在那里而不是函数产生相同的问题。我想知道这是不是模拟器的问题?虽然我以前从未遇到过这个问题。