Manage more Images to move in View

Posted by David Pollak on Stack Overflow See other posts from Stack Overflow or by David Pollak
Published on 2010-04-03T09:04:55Z Indexed on 2010/04/03 9:13 UTC
Read the original article Hit count: 180

Filed under:
|
|
|
|

hi everyone, I'm creating an app which has more UIImageView on a View, they should move normally from a side to the other. I have an issue: after entering the second image, the two UIImageView start to behave crazy (!) because they don' move freely, but they are like restricted in two different areas not touching each other even if I said different things

the first thing that I want to do, is to let them move normally; this is the code I am using:

`- (void)viewDidLoad { [super viewDidLoad];

pos = CGPointMake(14.0, 7.0);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

}`

- (void) onTimer {
pallone.center = CGPointMake(pallone.center.x+pos.x, pallone.center.y+pos.y);

if(pallone.center.x > 320 || pallone.center.x < 0)
    pos.x = -pos.x;
if(pallone.center.y > 480 || pallone.center.y < 0)
    pos.y = -pos.y;

}

and for the other image that has to enter after:

- (IBAction)spara{
cos = CGPointMake(8.0, 4.0);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(inTimer) userInfo:nil repeats:YES];

}

- (void)inTimer{
bomba.center = CGPointMake(bomba.center.x+pos.x, bomba.center.y+pos.y);

if(bomba.center.x > 50 || bomba.center.x < 0)
    pos.x = -pos.x;
if(bomba.center.y > 480 || bomba.center.y < 0)
    pos.y = -pos.y;

}

what should I change ? and if I'd like the images to move only in one way (y) ? how do I do this ?

I know, I'm a newbie

thanks in advance

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c