Multiple Images Falling Issues on XCODE

Joined
Mar 8, 2014
Messages
1
Reaction score
0
Points
1
Please help... I have this code on 3 images (stars) goes down on my game. The difference between stars codes is the delay timing on perform.

[self performSelector:mad:selector(star1Animation) withObject:nil afterDelay:2.0];
star1 = 2.0 seconds, star2 = 4.0 seconds and star3 = 6.0 seconds

When I load the game the star 1 goes down fine, but should be fall again on the next 2 seconds, this never happen. 4 seconds later, falling the star2 and on 6 seconds later falling the star3. The problem is: Star 1 never go down again until all the stars goes down. Then, for some reason, All the stars fall at the same time like 15 seconds later. Please Help. What I miss? Thanks for your help.

Here the Code .m file

-(void)star1Animation
{
// drop1 Down Movement Speed
star1tm = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:mad:selector(star1Code) userInfo:nil repeats:YES];
star2tm = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:mad:selector(star1Code) userInfo:nil repeats:YES];
star3tm = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:mad:selector(star1Code) userInfo:nil repeats:YES];
}

-(void) star1Code
{
star1.center = CGPointMake(star1.center.x, star1.center.y +2);

if (star1.center.y > 590) {
ramdomPosition = arc4random() %265;
ramdomPosition = ramdomPosition +54;
star1.center = CGPointMake(ramdomPosition, -60);

// Time to Show drop1 Again in x Seconds
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];

}
}

-(void)star2Animation
{
// drop2 Down Movement Speed
star2tm = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:mad:selector(star2Code) userInfo:nil repeats:YES];
}

-(void) star2Code
{
star2.center = CGPointMake(star2.center.x, star2.center.y +2);

if (star2.center.y > 590) {
ramdomPosition = arc4random() %265;
ramdomPosition = ramdomPosition +54;

star2.center = CGPointMake(ramdomPosition, -60);

// Time to Show drop1 Again in x Seconds
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:4.0]];
}
}

-(void)star3Animation
{
// drop3 Down Movement Speed
star3tm = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:mad:selector(star3Code) userInfo:nil repeats:YES];
}

-(void) star3Code
{
star3.center = CGPointMake(star3.center.x, star3.center.y +2);

if (star3.center.y > 590) {
ramdomPosition = arc4random() %265;
ramdomPosition = ramdomPosition +54;
star3.center = CGPointMake(ramdomPosition, -60);

// Time to Show drop1 Again in x Seconds
[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:6.0]];

}
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self performSelector:mad:selector(star1Animation) withObject:nil afterDelay:2.5];
[self performSelector:mad:selector(star2Animation) withObject:nil afterDelay:4.5];
[self performSelector:mad:selector(star3Animation) withObject:nil afterDelay:6.5];
}
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top