gpt4 book ai didi

swift - 具有纹理的物理 body 会减慢 fps

转载 作者:行者123 更新时间:2023-11-30 11:58:29 25 4
gpt4 key购买 nike

我有一个游戏,屏幕上同时有大约 8 个 SKPhysicsBodies,其中两个只是简单的正方形,并且是用纹理创建的。纹理并没有太复杂,这是一张图片:https://imgur.com/a/qJXL7 (黑色是透明的)。问题是,每次我生成一个使用纹理创建的PhysicsBody 时,游戏都会卡住几毫秒,从而破坏整个游戏,我怎样才能提高游戏的性能?这是我创建物理主体的方法:

createObstacle1() {
let obstTexture1 = SKTexture(imageNamed: "obst1")
let obst1 = SKSpriteNode()
obst1.size = CGSize(width: 30, height: 30)
obst1.color = player.color
obst1.zPosition = 3
obst1.physicsBody = SKPhysicsBody(texture: obstTexture1, size: obst1.size)
obst1.physicsBody?.affectedByGravity = false
obst1.physicsBody?.allowsRotation = false
obst1.physicsBody?.isDynamic = false
obst1.physicsBody?.restitution = 0
obst1.physicsBody?.linearDamping = 0
obst1.physicsBody?.angularDamping = 0
obst1.physicsBody?.friction = 0
obst1.physicsBody?.categoryBitMask = 3
obst1.physicsBody?.collisionBitMask = 1
obst1.physicsBody?.contactTestBitMask = 1
obst1.name = "obst1"

self.addChild(obst1)
}

最佳答案

您何时何地制造了障碍?我想正如 Knight0fdragon 所说,您必须尝试创建更新事件。愚蠢的问题。您在真实设备还是模拟器上进行测试?

敬礼,约瑟夫·M

关于swift - 具有纹理的物理 body 会减慢 fps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519433/

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