我想制作一个简单的 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