0

How can I change this number "63" in my code?

-(void)up
{


    [UIView animateWithDuration:[self randomFloatBetween:1.0 and:0.3] animations:^{
        m1.center = CGPointMake(63, 210);
    }];


   [self performSelector:@selector(down) withObject:nil afterDelay:[self randomFloatBetween:1.0 and:0.5]];
 }

Number 63 from my CGPointMake should be random. So For number 63 I need to be random these numbers: 160 & 257.

My "m1" image, appear at CGPointMake(63, 210), BUT I want to make Point 63 random, to change from 63 to 160 or 257. RANDOM. Thnaks a lot.

user1625435
  • 153
  • 8

2 Answers2

1

Add the desired numbers to an NSArray, and select the number with [yourArray objectAtIndex:(arc4random()%yourArray.count)];

Martol1ni
  • 4,684
  • 2
  • 29
  • 39
1
-(void)up
{
    NSArray *myArray = [NSArray arrayWithObjects:[NSNumber numberWithFloat:63],[NSNumber numberWithFloat:160],[NSNumber numberWithFloat:257], nil];
    [UIView animateWithDuration:[self randomFloatBetween:1.0 and:0.3] animations:^{
        m1.center = CGPointMake([[myArray objectAtIndex:arc4random() % [myArray count]] floatValue], 210);
    }];
    [self performSelector:@selector(down) withObject:nil afterDelay:[self randomFloatBetween:1.0 and:0.5]];
}

Maybe this will help.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281