我在游戏中有大量相同的节点都是随机生成的,当我自己运行项目时,它运行得非常顺利。然而,当我使用这个物理体(或任何物理体)时,它会大大减速:
circle.physicsBody = SKPhysicsBody(circleOfRadius: 25)
我该如何解决这个问题?如有必要,将发布更多代码。
编辑:
func createCirclesOnLine(line: CGFloat) {
var currentY : CGFloat = -110000
let maxY = self.size.width * 15
let spacing : CGFloat = 120
while currentY < maxY {
let circle = SKSpriteNode(imageNamed: "first@2x")
circle.position = CGPointMake(line, currentY)
circle.physicsBody = SKPhysicsBody(rectangleOfSize: circle.size)
circle.physicsBody?.dynamic = false
circle.physicsBody?.restitution = 1
circle.size = CGSizeMake(75, 75)
let up = SKAction.moveByX(0, y: 9000, duration: 90)
circle.runAction(up)
foregroundNode.addChild(circle)
currentY += CGFloat((random() % 400) + 70)
}