swift - 不同的 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,那么它就会滞后。
解决方案
推荐阅读
- python-sphinx - sphinx:有没有办法将所有内容嵌入到单个 html 页面中?
- r - 为什么这个正则表达式模式匹配这个字符串?
- apache-spark - 包装 StructField 以在 from_avro() 中使用它
- python - 将嵌套列表转换为字典
- react-native - React Native Webview 不请求许可但仍然能够访问文件
- c++ - 在此代码中执行第一个表达式后,k 的值如何变为-5?
- r - 如何按行主要顺序排列表格?
- javascript - 如何替换 DOM 元素中的元素列表
- excel - Excel 中的工作表副本运行时错误
- postgresql - 有人用 MyBatis 配置过 SSL 吗?