gpt4 book ai didi

ios - 触摸Node的Swift访问方法

转载 作者:行者123 更新时间:2023-11-29 02:36:24 25 4
gpt4 key购买 nike

我使用以下方法拖动 SKSpriteNode

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch in touches {
let location = touch.locationInNode(self)
var touchedNode = nodeAtPoint(location)

if touchedNode.isKindOfClass(Card) {
touchedNode.position = location
}

}
}

if 语句确认它是一个特定的类,我现在如何调用方法和访问该节点的属性?

最佳答案

您可以使用以下语法:

    if let cardNode = touchedNode as Card {
cardNode.position = location
// cardNode is of type card. You can access all its
// methods and properties
}

关于ios - 触摸Node的Swift访问方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com