我正在创建一个SpriteKit游戏,该游戏涉及触摸掉落的目标。当前,目标太难捕捉到第一次触摸(touchesMoved:
),并且似乎只能通过提前放置手指( override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let positionInScene = touch.location(in: self)
print(positionInScene)
guard let touchedNode = self.nodes(at: positionInScene).first as? SKSpriteNode else { return }
if let dot = touchedNode.name {
if dot == "dot" {
removeTarget(touchedNode)
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let positionInScene = touch.location(in: self)
print(positionInScene)
guard let touchedNode = self.nodes(at: positionInScene).first as? SKSpriteNode else { return }
if let dot = touchedNode.name {
if dot == "dot" {
removeTarget(touchedNode)
}
}
}
)才能触摸目标。是否有一种用于减缓触摸或扩大触摸位置以使第一次触摸更有效的技术?我的代码现在看起来像这样:
db.tweets1.aggregate([
{ "$limit": 1 },
{ "$facet": {
"collection1": [
{ "$limit": 1 },
{ "$lookup": {
"from": "tweets1",
"pipeline": [
{ "$project": {
"_id":0, "utente_id": "$user_id", "TweetToken": "$TweetTokenizzato"
}}
],
"as": "collection1"
}}
],
"collection2": [
{ "$limit": 1 },
{ "$lookup": {
"from": "tweets2",
"pipeline": [
{ "$project": {
"_id":0, "utente_id": "$user_id", "TweetToken": "$TweetTokenizzato"
}}
],
"as": "collection2"
}}
]
}},
{ "$project": {
"data": {
"$concatArrays": [
{ "$arrayElemAt": ["$collection1.collection1", 0] },
{ "$arrayElemAt": ["$collection2.collection2", 0] },
]
}
}},
{ "$unwind": "$data" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ $out : "tweet_Final" }
])
答案 0 :(得分:2)
您的实体太小了吗?根据给定的信息,我在操场上重新创建了一个小场景,并且一切都按预期进行。如果我有一个显示的子节点,定义为
let circle = SKShapeNode(circleOfRadius: 20)
通过给定的touchesBe开始,我已经定义了SKScene的PhysicalWorld和SKNode的physicsBody,检测碰撞没有问题。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let location = touches.first?.location(in: self)
if self.atPoint(location) === circle {
print("TOUCH")
}
}
}