【发布时间】:2014-07-05 08:37:21
【问题描述】:
我想知道如何以逐渐增加的速度连续生成精灵。我确实看到了“如何逐渐增加某物的速率?”的问题。但我不确定如何将它应用到我的代码中。此外,如果有比使用游戏计时器更好的定期生成精灵的方法,请告诉我。
我尝试使用循环并增加“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];
}
感谢您的帮助。
【问题讨论】:
标签: sprite-kit timing