Sprite kit 如何快速繁殖精灵

Sprite kit 如何快速繁殖精灵,sprite-kit,timing,Sprite Kit,Timing,我想知道如何以逐渐增加的速度不断繁殖精灵。我确实看到了一个问题,那就是如何逐渐提高某事物的速度?但我不知道如何将它应用到我的代码中。此外,如果有比使用游戏计时器更好的方法定期生成精灵,请告诉我 我试着使用一个循环,让scheduledTimerWithTimeInterval增加,但结果只是导致大量精灵同时繁殖 -(void)getBalls { //[userScore.node removeFromParent]; SKSpriteNode *ball = [SKSpriteNode

我想知道如何以逐渐增加的速度不断繁殖精灵。我确实看到了一个问题,那就是如何逐渐提高某事物的速度?但我不知道如何将它应用到我的代码中。此外,如果有比使用游戏计时器更好的方法定期生成精灵,请告诉我

我试着使用一个循环,让scheduledTimerWithTimeInterval增加,但结果只是导致大量精灵同时繁殖

-(void)getBalls {


//[userScore.node removeFromParent];

SKSpriteNode *ball = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];

int x = arc4random() %320;

CGPoint myPoint = CGPointMake(x, 480);
ball.position = myPoint;

ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];

ball.physicsBody.categoryBitMask = ballCategory;

ball.physicsBody.contactTestBitMask = paddleCategory;

ball.physicsBody.collisionBitMask = ballCategory;

[self addChild:ball];

SKLabelNode *userScore = [SKLabelNode labelNodeWithFontNamed:@"Impact"];
userScore.fontColor = [SKColor blackColor];
userScore.text = [NSString stringWithFormat:@"SCORE: %i", score];
userScore.fontSize = 18;
userScore.position = CGPointMake(CGRectGetMidX(self.frame) + 110, CGRectGetHeight(self.frame)            
- 30);
[self addChild:userScore];
[userScore runAction:[SKAction fadeAlphaTo:1.0 duration:1.5] completion:^{
    [userScore removeFromParent];
}];




}

-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor  whiteColor];


self.physicsWorld.gravity = CGVectorMake(0, -9.8);
self.physicsWorld.contactDelegate = self;

gameTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self      
selector:@selector(getBalls) userInfo:nil repeats:YES];

[self addPlayer:size];


}

感谢您的帮助。

使用不重复的NSTimer。另外,在计时器调用的方法中,getBalls调用计时器并以线性、指数的方式降低间隔率,但您可以随意


谢谢这几乎是完美的。我希望decTime无限下降,所以我尝试这样做,如果decTime>-1{//linear increase decTime*=.1f;gameTimer=[NSTimer scheduledTimerWithTimeInterval:decTime目标:自选择器:@selectorgetBalls用户信息:无重复:否];}这是一个正确的方法吗,这样数字会不断地自我除法,而不是最终减去循环停止的条件?你必须自己去发现,我已经帮了你这么多了。
float decTime;
decTime = 1.5f;
-(id)initWithSize:(CGSize)size {

    if (self = [super initWithSize:size]) {
    self.backgroundColor = [SKColor  whiteColor];

    self.physicsWorld.gravity = CGVectorMake(0, -9.8);
    self.physicsWorld.contactDelegate = self;

    gameTimer = [NSTimer scheduledTimerWithTimeInterval:decTime target:self      
    selector:@selector(getBalls) userInfo:nil repeats:NO];

    [self addPlayer:size];

}

-(void)getBalls {


    //[userScore.node removeFromParent];

    SKSpriteNode *ball = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];

    int x = arc4random() %320;

    CGPoint myPoint = CGPointMake(x, 480);
    ball.position = myPoint;

    ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];

    ball.physicsBody.categoryBitMask = ballCategory;

    ball.physicsBody.contactTestBitMask = paddleCategory;

    ball.physicsBody.collisionBitMask = ballCategory;

    [self addChild:ball];

    ....

    if (decTime > .05f) {

        //linear increase
        decTime -= .01f;

        gameTimer = [NSTimer scheduledTimerWithTimeInterval:decTime target:self      
        selector:@selector(getBalls) userInfo:nil repeats:NO];

    }
}