Xcode 7 SpriteKit错误与块 [英] Xcode 7 SpriteKit Error with Blocks

查看:63
本文介绍了Xcode 7 SpriteKit错误与块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道为什么它在Xcode 7 GM中将不再起作用吗?

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.

下面是一个完整的示例.如果您从"New Sprite Kit游戏"中替换了默认的GameScene,则可以自己复制它.

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 {
}

发生的情况是场景正常工作,但触摸不再传递给父节点,即使userInteractionEnabled对于卡是假的,对于卡的父节点也是真(Stack: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)

因此,我用一个有效的测试用例对此进行了更新.这是一个错误,因为它可以在iOS 8.4 sim中使用,但不能在9 GM中使用.我已经提交给苹果了.

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.

推荐答案

这是一个错误.

我创建了一个测试器类来测试错误的存在并采取相应措施...

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

可以在此处

这篇关于Xcode 7 SpriteKit错误与块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆