【发布时间】:2014-08-14 20:43:09
【问题描述】:
我正在用 swift 创建一个游戏,其中涉及用字母组成单词。这些字母是单独的 SKSpriteNode,位于作为 SKSpriteNode 的“架子”上。为了从“架子”中删除字母,我试图介绍向上滑动。不幸的是,我遇到了字母被滑动的问题。架子似乎正在吸收它,有时甚至是 SKScene。我已禁用货架节点上的用户交互。
这是我的设置:
swipeRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("move:"))
swipeRecognizer.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipeRecognizer)
我将 swipeRecognizer 添加到视图中,然后在 move 方法中,我有以下内容:
func move(swipe:UISwipeGestureRecognizer){
if(swipe.state == UIGestureRecognizerState.Ended && swipe.numberOfTouches() == 1){
var touchLocation = swipe.locationInView(swipe.view)
touchLocation = self.convertPointFromView(touchLocation)
var sprite = self.nodeAtPoint(touchLocation)
if sprite is Letter{
let letter = sprite as Letter
if(gameManager.letterOnShelf(letter)){
gameManager.letterFlicked(letter)
}
}
}
}
只有有时它会将精灵识别为一个字母,80% 的时间精灵是架子,我不知道正确的工作方式是什么.....
非常感谢任何帮助。
大家加油!!
【问题讨论】:
-
可以发一张布局图吗?如果不是,这些字母是在黑板下方/上方吗?它们有多远?
-
zPosition 为:shelf.zPosition = 0 letter.zPosition = 3。对于添加到屏幕的所有字母。这能回答你的问题吗?
标签: ios swift sprite-kit ios8 uiswipegesturerecognizer