- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在用 Swift 编写一个基于 SpriteKit 的游戏。 SKScene 包含一个 SKSpriteNode,它包含 SKShapeNodes。其中一种形状是“玩家”。用户应该能够拖放播放器。我实现了不同的方法来让这个工作用户 touchesBegan、touchesMoved、touchesCanceled 和 touches Ended。 基本上一切正常,只要用户以正常速度拖动“播放器”。但是,如果用户拖动“播放器”非常快,则 touchesMoved 方法调用的次数不够多。我认为这可能是因为我使用了 SKShapeNodes 但基于输出(下方)似乎并非如此。
代码:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touchLocation = touches.first!.locationInNode(self)
if(self.player.containsPoint(touchLocation)){
self.startedTouchingPlayer()
}
super.touchesBegan(touches, withEvent: event)
print("TOUCHES BEGAN")
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touchLocation = touches.first!.locationInNode(self)
if(self.player.containsPoint(touchLocation)){
self.isTouchingPlayer(touchLocation)
print("TOUCHES MOVED \(touchLocation)")
}
super.touchesMoved(touches, withEvent: event)
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.endedTouchingHelper()
super.touchesEnded(touches, withEvent: event)
print("TOUCHES ENDED")
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
print("TOUCHES CANCELED")
self.endedTouchingHelper()
super.touchesCancelled(touches, withEvent: event)
}
打印语句:
正常运动:
TOUCHES BEGAN
TOUCHES MOVED (-4.0, -241.499984741211)
TOUCHES MOVED (0.500015258789062, -239.0)
TOUCHES MOVED (4.0, -237.000015258789)
TOUCHES MOVED (11.0, -234.0)
TOUCHES MOVED (19.5, -229.499984741211)
TOUCHES MOVED (27.0000152587891, -225.499984741211)
TOUCHES MOVED (34.0, -221.499984741211)
TOUCHES MOVED (41.0, -217.499984741211)
TOUCHES MOVED (48.0, -213.499984741211)
TOUCHES MOVED (53.4999847412109, -210.0)
...
TOUCHES MOVED (77.5, -177.000015258789)
TOUCHES MOVED (77.5, -178.0)
TOUCHES ENDED
快速移动:
TOUCHES BEGAN
TOUCHES MOVED (6.5, -277.5)
TOUCHES MOVED (3.0, -261.000030517578)
[*** at this point the finger is at a different position as the "player" ***] TOUCHES ENDED
感谢任何形式的帮助。谢谢。
最佳答案
你还没有发布你如何移动你的玩家,所以我假设你只是改变了你的玩家位置。我建议您使用 SKAction
来移动您的播放器。
func moveToPosition(oldPosition: CGPoint, newPosition: CGPoint) {
let xDistance = fabs(oldPosition.x - newPosition.x)
let yDistance = fabs(oldPosition.y - newPosition.y)
let distance = sqrt(xDistance * xDistance + yDistance * yDistance)
let sceneDiagonal = sqrt(world.frame.size.width * world.frame.size.width + world.frame.size.height * world.frame.size.height)
self.runAction(SKAction.moveTo(newPosition, duration: Double(distance / sceneDiagonal / 2)))
}
world -
SKNode
of exactly same size as yourSKScene
然后像这样使用它:touchesMoved
:
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touchLocation = touches.first!.locationInNode(self)
if(self.player.containsPoint(touchLocation)){
moveToPosition(self.player.position, newPosition: touchLocation)
}
关于ios - SpriteKit - touchesMoved 调用不够频繁 - 快速移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33853488/
我有一个包含值的字符串数组(duh...)。 有没有一种简单的方法可以获取出现次数最多的条目?有点像 values[37].getMostOften(); 干杯:) 最佳答案 您可以使用GroupBy
我目前正在将一款用 C#(适用于 Windows Phone)开发的游戏移植到 Java (Android)。 我们在 Java 版本中遇到了内存问题,在分析之后,似乎是由于内存中的大量 String
对于播放音频文件的 iPhone 应用程序,我正在开发一个系统来跟踪用户在他们听过的任何一集中的进度(例如,他们听 file1 的前 4:35,然后开始另一个文件,然后返回到文件 1,它从 4:35
如果您按下 UIbutton 显示 UITextView,将请求代码 Ì 再次按下 UIbutton 再次显示 UITextView :/ 最佳答案 .h 文件中只有一个 int 变量,如下所示..
我在 Application_End 上处理的项目中使用临时数据库: protected void Application_End() { if (_db != null) _db.Dispo
我是一名优秀的程序员,十分优秀!