iphone app内存增加

时间:2014-04-22 03:16:54

标签: objective-c ios7 sprite-kit

试图诊断为什么我的游戏正在积累内存,导致它最终放慢到没有反应的程度。基于之前提出的问题,我想我可能知道是什么导致它,但不确定,所以我会发布我认为可能的内容。

[self performSelector:@selector(createObstacle0) withObject:nil afterDelay:1.0];
[self performSelector:@selector(score0) withObject:nil afterDelay:1];

....

-(void)createObstacle0 {
int yMin = (CGRectGetMidY(self.frame)+190);
int yMax = (CGRectGetMidY(self.frame)+270);
CGPoint startPoint = CGPointMake(-20, yMin + arc4random_uniform(yMax - yMin));
SKSpriteNode *obstacle = [SKSpriteNode spriteNodeWithImageNamed:@"obstacle"];
obstacle.position = CGPointMake(startPoint.x, startPoint.y);
obstacle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:21.5];
obstacle.physicsBody.categoryBitMask = enemyCategory;
obstacle.physicsBody.contactTestBitMask = playerCategory;
obstacle.physicsBody.dynamic = NO;
obstacle.name = @"obstacle0";
[self addChild:obstacle];
[obstacle runAction:[SKAction moveTo:CGPointMake(340, startPoint.y) duration:minTime + arc4random_uniform(maxTime - minTime)]];
float randomNum = arc4random_uniform(3.0) + 0.1;
[self performSelector:@selector(createObstacle0) withObject:nil afterDelay:randomNum];
}

-(void)score0 {

[self enumerateChildNodesWithName:@"obstacle0" usingBlock:^(SKNode *node, BOOL *stop) {
    if (node.position.x > 330) {
        score++;
        scorelabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)score];
        [node removeFromParent];
    }

}];
[self performSelector:@selector(score0) withObject:nil afterDelay:.1];
}

我在这里读到perferomSelector会导致一些内存问题。对我来说,在玩了一次游戏后,我可以坐在主菜单上,cpu和内存都会继续上升。不知道发生了什么,并感谢所有的帮助。这是我责备的代码吗?

0 个答案:

没有答案