3

我想制作一个简单的 SpriteKit 应用程序,我可以在其中添加“岩石”,它们会落到屏幕底部。就像这样:http ://aamukasa.fi/II-13-347 。实现非常简单,但是当节点超过 100 个时,我会遇到巨大的性能问题。当所有块碰撞在一起时,FPS 会低于 10。有没有办法通过良好的 FPS 和大约 300-400 块来实现这种功能?

@implementation MyScene

-(id)initWithSize:(CGSize)size {    
if (self = [super initWithSize:size]) {
    /* Setup your scene here */

    self.backgroundColor = [SKColor colorWithWhite:1 alpha:1];
    self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
    self.scaleMode = SKSceneScaleModeAspectFit;


}
return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

for (UITouch *touch in touches) {
    CGPoint location = [touch locationInNode:self];

    SKSpriteNode *rock = [[SKSpriteNode alloc] initWithColor:[SKColor blackColor]     size:CGSizeMake(20,10)];
    rock.position = location;
    rock.name = @"rock";
    rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
    [self addChild:rock];

}
}

-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}

@end
4

3 回答 3

2

你可能想尝试给你的岩石一个圆形的物理体。我认为它不会解决问题,但可能会提高帧率!据我了解,圆形物理体的性能优于矩形物理体。

于 2013-09-24T05:38:18.947 回答
0

You should test on a device to see actual FPS. In the simulator I get 60 FPS until I reach 200 bricks.

Then it starts dropping but on the device you could get better results.

于 2013-10-05T17:45:04.540 回答
0

不确定你是否还在寻找,但可以尝试这样的事情:

-(void)didSimulatePhysics
{
    [self enumerateChildNodesWithName:@"rock" usingBlock:^(SKNode *node, BOOL *stop) {
        if (node.position.y < 0)
            [node removeFromParent];
    }];
}

否则节点将留在内存中,FPS 会随着时间的推移而恶化。

于 2014-02-05T08:02:37.450 回答