首页 > 解决方案 > 不同的 SKTexture 会导致疯狂的延迟

问题描述

我尝试为游戏制作两个相同的字符(从 SKSpriteNode 扩展的两个类),唯一的区别是他们使用的 SKTexture。我将它们称为 A 和 B。每当我让 A 发射子弹时,它不会滞后,但当我让 B 发射子弹时,它会滞后一点。当我从 A 发送垃圾邮件时,问题变得很明显,它保持在恒定的 60 FPS 但当我从 B 发送垃圾邮件时,它会滞后,降至 50 FPS 左右。

A 的纹理是“Lampy.png”,我尝试将 B 的纹理设置为“Lampy2.png”。那两张图片完全一样,唯一的区别是文件名,但B滞后。

override init(){
        super.init()
        playerBody.texture = SKTexture(imageNamed: "Lampy2")
}

上面的代码来自 B 并且滞后

override init(){
        super.init()
        playerBody.texture = SKTexture(imageNamed: "Lampy")
}

上面的代码来自 A 并且没有滞后

两个类的其他部分完全相同。我是否错误地导入了图像或什么?我不记得我是如何导入 Lampy 的,但对于 Lampy2,我将它直接从 Finder 拖到 assets 文件夹中。

编辑 - 这是完整的课程代码

import Foundation
import SpriteKit

class Lampy: Player{

    override init(){
        super.init()
        playerBody.texture = SKTexture(imageNamed: "Lampy")
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func shoot(){
        let thiccBullet = Thicc()
        thiccBullet.position = position
        thiccBullet.bulletBody.zRotation = playerBody.zRotation
        thiccBullet.owner = self;
        parent?.addChild(thiccBullet)
    }


}

如果我将LampyplayerBody.texture = SKTexture(imageNamed: "Lampy") 更改为 Lampy2,那么它就会滞后。

标签: swiftxcodesprite-kit

解决方案


推荐阅读