Sprite Kit, adding SKNode in a block as an action results in touches not being transferred
Originator: | visskiss | ||
Number: | rdar://22700000 | Date Originated: | 9/14/2015 |
Status: | Closed | Resolved: | Yes |
Product: | Sprite Kit | Product Version: | 9.0 |
Classification: | Bug | Reproducible: | Yes |
Replace the default GameScene in a new Sprite Kit game with the following: import SpriteKit class GameScene: SKScene { override func didMoveToView(view: SKView) { /* Setup your scene here */ let card = Card(imageNamed: "card_background_blank") card.name = "Card" let stack = Stack(imageNamed: "stack_background") stack.name = "Stack" addChild(stack) stack.addChild(card) card.position = CGPointMake(100,100) stack.zPosition = 1 card.zPosition = 1 stack.position = CGPointMake(506,428) card.userInteractionEnabled = false stack.userInteractionEnabled = true } override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { print("Touch") moveAllCardsAndReturn() } func moveAllCardsAndReturn () { var wait:NSTimeInterval = 1.0 let waitIncrement:NSTimeInterval = 0.05 let duration:NSTimeInterval = 0.15 func removeAndMove(card:Card) { let oldParent = card.parent card.removeFromParent() addChild(card) card.position = CGPointMake(500,48) card.runAction(SKAction.waitForDuration(wait)) { card.removeFromParent() oldParent!.addChild(card) card.position = CGPointMake(-100,100) } wait += waitIncrement } let stack = childNodeWithName("Stack") let card = stack?.childNodeWithName("Card") removeAndMove(card as! Card) } override func update(currentTime: CFTimeInterval) { /* Called before each frame is rendered */ } } class Stack:SKSpriteNode { override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { print("Stack Touch") } } class Card:SKSpriteNode { } When you touch the background scene, it will remove the node from the stack, add it to itself. Then, after 1 second it will add the node back to the stack. Although it is rendered, it does not activate the "touchesBegan" etc of the parent node (as it should).
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!