我是 iPhone 编程的新手,目前正在开发分球游戏。在这个游戏中,当我的子弹击中任何球时,我希望它产生两个新球。我的子弹和球都是uiimageview。
这是我的代码:
if ((CGRectIntersectsRect(bullet.frame,Ball.frame)) && !(ball)){
ball=TRUE;
x=Ball.frame.origin.x;
y=Ball.frame.origin.y;
[self performSelector:@selector(createball)];
}
这是我的创建球功能..
-(void)createball{
if (ball) {
imageMove1 = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,50 ,50)];
UIImage *imag = [UIImage imageNamed:@"ball1.png"];
[imageMove1 setImage:imag];
[self.view addSubview:imageMove1];
[ballArray addObject:imageMove1];
imageMove2 = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,50 ,50)];
UIImage *imag1 = [UIImage imageNamed:@"ball1.png"];
[imageMove2 setImage:imag1];
[self.view addSubview:imageMove2];
[ballArray addObject:imageMove2];
ball=FALSE;
[self performSelector:@selector(moveball)];
}
}
现在在创建这两个 uiimgeview 之后,当子弹击中这两个 uiimageview 之一时,我希望它创建另外两个 uiimageview。但是我面临的问题是我们如何获得这些新的 uiimageview 的框架......