如何在没有延迟的情况下在同一个角色的多个动画之间平滑过渡?
我正在使用跳跃角色在iOS Swift中开发游戏。此角色有一些动画,如基本动画,跳跃动画和着陆动画。
我为每个动画设置纹理图集如下:
// Basic
let surferBasicAnimatedAtlas = SKTextureAtlas(named: "surfer_basic.atlas")
let numImages = surferBasicAnimatedAtlas.textureNames.count
for var i=0; i<numImages; i++ {
let surferBasicTextureName = "surfer_basic_000\(i)"
self.surferBasicFrames.append(surferBasicAnimatedAtlas.textureNamed(surferBasicTextureName))
}
// Jump
let surferJumpAnimatedAtlas = SKTextureAtlas(named: "surfer_jump.atlas")
let numJumpImages = surferJumpAnimatedAtlas.textureNames.count
for var i=0; i<numJumpImages; i++ {
let surferJumpTextureName = "surfer_jump_000\(i)"
self.surferJumpFrames.append(surferJumpAnimatedAtlas.textureNamed(surferJumpTextureName))
}
// Landing
let surferLandingAnimatedAtlas = SKTextureAtlas(named: "surfer_landing.atlas")
let numLandingImages = surferLandingAnimatedAtlas.textureNames.count
for var i=12; i<numLandingImages; i++ {
let surferLandingTextureName = "surfer_landing_000\(i)"
self.surferLandingFrames.append(surferLandingAnimatedAtlas.textureNamed(surferLandingTextureName))
}
// Pick textures
self.surferWalkingFrames = surferBasicFrames
let firstFrame = surferWalkingFrames[0]
self.character = SKSpriteNode(texture: firstFrame)
self.character.runAction(SKAction.repeatActionForever(SKAction.animateWithTextures(surferWalkingFrames, timePerFrame: (1 / 30), resize: false, restore: true)), withKey:"surferBasic")
当我触摸屏幕时,基本动画应该停止并且应该运行跳转动画,但是会导致延迟。触摸后约一秒钟,跳跃动画开始。
我试过这个:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.character.removeActionForKey("surferBasic")
self.surferWalkingFrames = surferJumpFrames
self.character.runAction(SKAction.repeatActionForever(SKAction.animateWithTextures(surferWalkingFrames, timePerFrame: (1 / 30), resize: false, restore: true)), withKey:"surferJump")
}
如何在没有延迟的情况下在同一个角色的多个动画之间平滑过渡?
答案 0 :(得分:0)
我可能是错的,但看起来(1/30)是你的罪犯有几个原因。
我会首先尝试.2并查看是否会发生任何变化,如果确实如此,那么只需要找到更改纹理所需的速度。
希望这有帮助。