Xcode 7 SpriteKit Error with Blocks

醉酒当歌 提交于 2019-12-13 00:28:59

问题


Does anybody know why this won't work anymore in Xcode 7 GM?

I have debugged and verified, but even though the nodes are appearing on the scene, they no longer pass touch events to parent nodes.

Below is a fully working example. If you replace the default GameScene from the "New Sprite Kit Game" you can reproduce it yourself.

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        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)
            var sequence = [SKAction]()
            sequence.append(SKAction.waitForDuration(wait))
            sequence.append(SKAction.runBlock({
                card.removeFromParent()
                oldParent.addChild(card)
                card.position = CGPointMake(100,100)
            }))
            card.runAction(SKAction.sequence(sequence))
            wait += waitIncrement
        }
        let stack = childNodeWithName("Stack")
        let card = stack?.childNodeWithName("Card")
        removeAndMove(card as! Card)


    }

}

class Stack:SKSpriteNode {
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        print("Stack Touch")
    }
}
class Card:SKSpriteNode {
}

What happens is the scene works correctly, but touches no longer pass to the parent node, even though userInteractionEnabled is false for the card and true for the parent node of the card (a Stack:SKSpriteNode)

So, I have updated this with a working test case. It is a bug, as it works in iOS 8.4 sim, but not in 9 GM. I have submitted it to apple.


回答1:


This is a bug.

I have created a tester class to test for the presence of the bug and act accordingly...

Can be found here



来源:https://stackoverflow.com/questions/32535246/xcode-7-spritekit-error-with-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!