gpt4 book ai didi

ios - 点击屏幕时的小延迟/抖动

转载 作者:行者123 更新时间:2023-11-29 01:23:04 26 4
gpt4 key购买 nike

所以我的游戏几乎完成了...但是当我将手指按住屏幕时会出现这种小故障或抖动,现在我已经注意到了,我无法不注意到...

它发生得非常快,并且只有在调用一个函数来处理点击和按住(长按)时才会发生。这会在使用计时器经过 0.2 秒后发生。

我已经尝试对其设置断点以确定代码中发生抖动的确切位置,但似乎我无法对其进行微调以找到它。

我的更新方法是典型的:

override func update(currentTime: CFTimeInterval) {

//calc delta time
if lastUpdateTime > 0 {
dt = currentTime - lastUpdateTime
} else {
dt = 0
}
lastUpdateTime = currentTime

//timer for handleLongPress
if touched {
longTouchTimer += dt
}

if longTouchTimer >= 0.2 && !canLongPressNow {
canLongPressNow = true
handleLongPress()
} else {
canLongPressNow = false
}

...
//switch GameSate
//switch CharacterState
}

我处理LongPress的函数是这样的:

func handleLongPress() {
//switch gameState
//if in gameplay gamestate
if canLongPressNow {
//rotate player
//change character state
startPlayerAnimation_Sliding()
}
touched = false
longTouchTimer = 0
}

startPlayerAnimation_Sliding() 只是迭代播放器节点的纹理数组。

func startPlayerAnimation_Sliding() {
var textures: Array<SKTexture> = []
for i in 0..<KNumSlideFrames{
textures.append(SKTexture(imageNamed: "slide\(i)"))
}
let playerAnimation = SKAction.animateWithTextures(textures, timePerFrame: 0.3)
player.runAction(SKAction.repeatActionForever(playerAnimation), withKey: "sliding")
}

是否有任何明显的原因可能导致此问题?

更新

我已经从我的 update(..) 方法中删除了它,它看起来又很顺利了……我不知道为什么……?也许是因为它正在删除尚未创建的 key (爆炸)?或者它每帧都删除这些键的事实......虽然没有意义......但我称之为晚上,明天再看这个。感谢您一直以来的帮助。晚上好。 (明天更新)

    //for animations
switch characterState {
case .Running:
player.removeActionForKey("exploding")
player.removeActionForKey("sliding")
break
case .Sliding:
player.removeActionForKey("running")
player.removeActionForKey("exploding")
break
case .Exploding:
player.removeActionForKey("running")
player.removeActionForKey("sliding")
break
}

最佳答案

哎呀,你创建纹理的方式会大大降低你的速度,每次触摸发生时你都在创建新纹理,这是不需要的。而是这样做:

var textures: Array<SKTexture> = []
var playerAnimation : SKAction?
func loadingPhase() //however this is defined for you
{
for i in 0..<KNumSlideFrames{
textures.append(SKTexture(imageNamed: "slide\(i)"))
}
playerAnimation = SKAction.repeatActionForever(SKAction.animateWithTextures(textures, timePerFrame: 0.3))

}
func startPlayerAnimation_Sliding() {


player.runAction(playerAnimation!, withKey: "sliding")
}

关于ios - 点击屏幕时的小延迟/抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34365093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com