我正在用 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 -
SKNodeof 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/
我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby数组,我们在StackOverflow上找到一
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里