开发者

controlling the number of random generating elements

I am generating random fireballs, but my problem that it's generating much number of fireballs .

How can I control the number of generated fireballs?

- (void)onTimer
{
    // build a view from our fire image
    UIImageView* fireView = [[UIImageView alloc] initWithImage:fireballs];


    int startX = round(random() % 320);
    int endX = round(random() % 320);
    double scale = 1 / round(random() % 100) + 1.0;
    double speed = 1 / round(random() % 100) + 1.0;


    fireView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);



    [self.view addSubview:fireView];

    [UIView beginAnimations:nil context:fireView];

    [UIView setAnimationDuration:5 * speed];


    fireView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 开发者_如何学C25.0 * scale);

    [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];

}


You probably need to adjust how often your are firing your timer. Here's an example, just change your code where the "2.0" is below:

[NSTimer scheduledTimerWithTimeInterval:2.0
    target:self
    selector:@selector(targetMethod:)
    userInfo:nil
    repeats:NO];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜