我正在使用 SpriteKit 中的 Swift 在 Xcode 6 Beta 6 中编写代码。在代码中,当用户移动手指时,我需要一张图片来跟随手指。 touchesMoved 有效但有小故障。如果我慢慢移动手指,一切都很好。如果我从右向左快速移动手指,那么一切都很好。如果我从左到右快速移动手指,那么图片只会跟随手指几分之一秒。如果我在当前位置点击并按住图片大约半秒钟,那么当我从右到左或从左到右快速移动它时,一切都很好。总之,除非我点击并按住图片大约半秒钟,否则我无法从左到右快速移动图片。有人知道为什么会这样吗?谢谢你的时间。下面是代码。我正在移动 SKSPriteNode follow2
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let angle_area_location = touch.locationInNode(self)
if self.nodeAtPoint(angle_area_location) == self.angle_area {
if (angle_area_location.x <= 21) {
angle = 1.55681122463001
distance12 = sqrt((angle_area_location.y - 30) * (angle_area_location.y - 30) + 1)
}
if (angle_area_location.y <= 31) {
angle = 0.0102037274939542
distance12 = sqrt((31 - 30) * (31 - 30) + (angle_area_location.x - 20) * (angle_area_location.x - 20))
}
if (angle_area_location.x > 21) && (angle_area_location.y > 31) {
angle = atan((angle_area_location.y - 30) / (angle_area_location.x - 20))
distance12 = sqrt((angle_area_location.y - 30) * (angle_area_location.y - 30) + (angle_area_location.x - 20) * (angle_area_location.x - 20))
}
if (distance12 <= maxFollow2) && (distance12 >= minFollow2) {
self.cannon.zRotation = angle
self.arc.zRotation = angle
if (angle_area_location.x > 21) || (angle_area_location.y > 31) {
follow2.position = CGPointMake(angle_area_location.x , angle_area_location.y)
}
if(angle_area_location.x <= 21) {
follow2.position = CGPointMake(21 , angle_area_location.y)
}
if (angle_area_location.y <= 31) {
follow2.position = CGPointMake(angle_area_location.x , 31)
}
}
if(distance12 > maxFollow2) {
self.cannon.zRotation = angle
self.arc.zRotation = angle
delta = 290/3
arc.size = CGSizeMake(160 * (1 + delta/20) , 35)
arc.position = CGPointMake(20 - 3 * (delta) * cos(angle) , 30 - 3 * (delta) * sin(angle))
followdist = 360
follow2.position = CGPointMake(angle_area_location.x , angle_area_location.y)
velocity = vmin + (followdist - minFollow2) * (300/(maxFollow2 - minFollow2))
}
if (distance12 < minFollow2) {
self.cannon.zRotation = angle
self.arc.zRotation = angle
arc.size = CGSizeMake(160 , 6.8)
arc.position = CGPointMake(20 , 30)
follow2.position = CGPointMake( minFollow2 * cos(angle) + 20 , minFollow2 * sin(angle) + 30)
followdist = sqrt((follow2.position.y - 30) * (follow2.position.y - 30) + (follow2.position.x - 20) * (follow2.position.x - 20))
velocity = vmin + (followdist - minFollow2) * (300/(maxFollow2 - minFollow2))
}
}
}
}
最佳答案
好的,我发现了故障。我有一个 UISwipeGestureRecognizer,它在我向右滑动时调用一个方法。我停用了它,一切正常。我想在 touchesMoved 上向右滑动和从左向右移动会相互干扰。
关于swift - TouchesMoved swift 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25655202/
当我在2个浏览器之间设置数据通道时(在同一网络上的2台不同机器上进行测试),在以下2种情况下,我得到了关于延迟的不同结果。情况一:只发送/接收当我将一侧设置为以例如70毫秒的间隔发送测试消息时,我看到它们从另一侧传入,没有明显的延迟。每条收到消息之间的时间接近70毫秒。到目前为止一切顺利。情况2:双方轮流发送和接收当我将双方设置为在收到来自另一方的消息后立即发送消息并且自上次发送以来已超过70毫秒时,一切正常,但有时除外。每隔几秒(不一致),我测量到约1000毫秒的延迟。奇怪的是,绝大多数消息之间的时间要么~1000毫秒。我在chrome和firefox(的组合)中测试了这两种情况,行
当我将time.Now()编码到JSON对象时,它给出的结果为"2009-11-10T23:00:00Z"但打印时间。现在给出2009-11-1023:00:00+0000UTC。他们为什么不同。什么是T和Z。另外,如何根据this将其转换为swiftNSDate对象?表? 最佳答案 这些值的含义无关紧要,它们是该格式(ISO8601)的一部分。有几种方法可以解决这个问题。一种是为时间或您的结构定义自定义MarshalJSON()方法并使用它来格式化日期,另一种是首先在您的结构中将其表示为字符串,以便当默认实现执行你得到你正在寻找的
在C/C++/Java/Go中,我们使用,来分隔参数:(aint,bint)在ObjectiveC中,我们使用:来表示参数::(int)a:(int)b在Swift中,我们必须同时使用:和,:(a:int,b:int)是否需要冗余? 最佳答案 Swift可能有外部和内部参数名称:(externalinternal:Int)如果没有独特的分隔符,会产生很多歧义。 关于objective-c-为什么Swift函数定义语法是多余的?,我们在StackOverflow上找到一个类似的问题:
我的Swift应用程序与用Go编写的服务器通信。我希望使用Zlib压缩传输的数据,但压缩结果似乎与Swift和Go不同。这是Go版本:sourceString:="A-t-ellebesoind'autrespreuves?Acceptez-lapourleplaisir.J'aitantfaitquedelacueillir,Etc'estpresqueunefleur-des-veuves."//Compressionvarbbytes.Bufferwriter:=zlib.NewWriter(&b)writer.Write([]byte(sourceString))writer.
我正在使用rsaEncryptionOAEPSHA256AESGCM在iOS上使用SecKeyCreateEncryptedData加密一些数据,然后在golang后端解密相同的数据。我正在使用3072位rsa公钥来加密对称key。当我从iOS获取数据到后端时,我能够成功解密对称key,但gcm标签验证失败。我使用的是与iOS相同的16字节IV,但不知道iOS在加密时是否使用任何aad(附加身份验证数据)。有谁知道rsaEncryptionOAEPSHA256AESGCMforiOS是否使用了一些aad?这适用于iOS10+。我已经尝试过使用nil、空的16字节数组、aeskey本身、
我使用swiftyJSON从apiurl消费OData。这里的apiurl与VPN连接。并且apiurl看起来像http://192.xxx.xx.xx:8000/sap/opu/odata/sap/Z_SRV/PRListSetSet?$format=json当我在模拟器中运行时,我可以从odataapiurl获取数据,但是在设备中运行时,没有从odataapiurl接收到数据。由于没有vpn连接到移动设备。我如何以编程方式对我的VPN进行硬编码以在移动设备中接收数据?这是我如何从ODataapiurl获取数据:typealiasServiceResponse=(JSON,Error
我正在开发一个涉及一些XML解析的自定义框架,使用Kanna框架。每当我尝试将我的框架导入playground时,playground就会崩溃并出现以下错误:Playgroundexecutionfailed:expressionfailedtoparse,unknownerror*thread#1:tid=0x4e9448,0x00000001074bf360com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground,queue='com.apple.main-thread',stopreason=breakpoint1.1*
我尝试在Windows10上的Ubuntu上的bash上安装Swift4我的Ubuntu版本:我@DESKTOP:~$lsb_release-a没有可用的LSB模块。经销商ID:Ubuntu描述:Ubuntu16.04.3LTS发布:16.04代号:xenial我做了apt-getupgrade和apt-getupdate我遵循Linux步骤here:安装Swift4最终我得到了错误:我@DESKTOP:~$swift/home/me/swift4/swift-4.0.2-RELEASE-ubuntu16.04/usr/bin/lldb:加载共享库时出错:libpython2.7.so
问题我有一个大小合适的javaFX窗口,在我调整应用程序中任何窗口的大小之前,它看起来运行良好。调整大小后,所有具有下拉或类似操作的组件(即Menu、ComboBox、TabPane)变得非常慢。原因我已将问题缩小到进度条,如果我从场景中删除进度条,我可以根据需要调整窗口的大小,如果我添加它,那么任何窗口都会调整大小,它们开始变成大约半秒钟没有反应;如果我进行大量调整,有时需要两秒钟。窗口窗口View,以便您可以看到所有组件。我无法添加所有窗口代码,因为它的发布方式太多了。带进度条的类/***Theclassthatholdsanddisplaystheprogressbar*/pub
我正在试验lidgren在XNA中,我遇到了一些“滞后”问题。我已经下载了他们的XNAsample并注意到即使他们的样本也滞后。问题是,另一侧的移动并不流畅,我正在LAN(实际上是在同一台计算机上)而不是通过Internet进行尝试。有没有人因为与lidgren和XNA的连接滞后而遇到同样的运动不流畅的问题? 最佳答案 您直接链接的示例将位置设置为从网络接收到的任何位置,这对于多人游戏来说是个坏主意!在真实游戏中你应该做的是在本地位置和远程位置之间进行插值。因此,您的接收方法看起来有点像这样:voidReceive(packet){