- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够用手指移动 Sprite 。我首先有一个变量来判断手指是否在 Sprite 上:
var isFingerOnGlow = false
然后我有 touchesBegan
函数,如果用户触摸 Sprite ,我会更改上述变量的值:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
var touch = touches.anyObject() as UITouch!
var touchLocation = touch.locationInNode(self)
if let body = physicsWorld.bodyAtPoint(touchLocation) {
if body.node!.name == GlowCategoryName {
println("Began touch on hero")
isFingerOnGlow = true
}
}
}
有时可以,控制台显示“begin touch on hero”,有时则不行。有没有更好的方法来编写第一部分的代码?
然后我想知道我下面的touchesMoved
代码是否有效:
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
if isFingerOnGlow{
var touch = touches.anyObject() as UITouch!
var touchLocation = touch.locationInNode(self)
var previousLocation = touch.previousLocationInNode(self)
var glow = SKSpriteNode(imageNamed: GlowCategoryName)
// Calculate new position along x for glow
var glowX = glow.position.x + (touchLocation.x - previousLocation.x)
var glowY = glow.position.y + (touchLocation.y - previousLocation.y)
// Limit x so that glow won't leave screen to left or right
glowX = max(glowX, glow.size.width/2)
glowX = min(glowX, size.width - glow.size.width/2)
glow.position = CGPointMake(glowX, glowY)
}
}
...
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
isFingerOnGlow = false
}
最佳答案
您可以像这样修改函数来跟踪触摸。
var isFingerOnGlow = false
var touchedGlowNode : SKNode!
override func touchesBegan(touches: NSSet, withEvent event:UIEvent) {
var touch = touches.anyObject() as UITouch!
var touchLocation = touch.locationInNode(self)
let body = self.nodeAtPoint(touchLocation)
if body.name == GlowCategoryName {
println("Began touch on hero")
touchedGlowNode = body
isFingerOnGlow = true
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
if isFingerOnGlow{
let touch = touches.anyObject() as UITouch!
let touchLocation = touch.locationInNode(self)
let previousLocation = touch.previousLocationInNode(self)
let distanceX = touchLocation.x - previousLocation.x
let distanceY = touchLocation.y - previousLocation.y
touchedGlowNode.position = CGPointMake(touchedGlowNode.position.x + distanceX,
touchedGlowNode.position.y + distanceY)
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
isFingerOnGlow = false
}
关于ios - 如何用手指移动 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28436078/
我用 cocos2d 制作了我的第一个应用程序,所以我在这里很新 我的第一个问题: 我不会让物体(船)跟随我的手指。 -(void) ccTouchMoved:(UITouch *)touch wit
如果某人将右手压在扫描仪的玻璃上进行扫描,结果将如下所示: (没有橙色和白色注释)。我们如何确定某人的 2D:4D ratio从他们的手的图像? 最佳答案 您已经标记了这个很棒的 opencv - 我
我的 View Controller 中有几个 UIScrollView。我想覆盖一个通过 UIPanGestureRecognizer 捕获 2 根手指滑动的 View ,它不会记录 UIScrol
现在这真是令人困惑...在不离开页面的情况下更新 mysql 数据库...我有 3 位代码。 head 标签中的 javascript、body 中的操作按钮以及要在另一个页面上执行的代码。以下是三个
我有这段代码是从 Style clipboard in flutter 得到的 showMenu( context: context, // TODO: Positio
我是一名优秀的程序员,十分优秀!