Hi.
This is what I am trying to do. I am making a game that shoots by pressing a fire button. I want an image to be created every time the button is pressed. That part is easy. The problem is how do I track images so I can remove them individually?
What I am finding is that if I removeFromSuperview with a timer, all the views are removed including the ones that have just been created.
Is there a way to number views or images with a tag number or something so I can remove any view/image I need to.
For example: User presses the shoot button ten times and ten images come out. Now the enemy only touches images 4, 5, and 6, then those three images return a unique number so I can remove them and the rest continue on their paths without being removed.
Code:
CGRect myImageRect = CGRectMake(-x + Xposition,-y + Yposition, weaponSriteSize, weaponSriteSize);
CGRect myImageRect1 = CGRectMake(number / num, number2 / num, weaponSize, weaponSize);
cropView = [[UIView alloc] initWithFrame:myImageRect];
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect1];
[myImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",weaponImage]]];
myImage.opaque = YES; // explicitly opaque for performance
cropView.clipsToBounds = YES;
[cropView addSubview:myImage];
[weaponDistance addSubview:cropView];
[myImage release];
[cropView release];
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(weaponStop) userInfo:nil repeats:NO];
}
- (void)weaponStop {
[cropView removeFromSuperview];
}
I have removed the code that moves the projectile/image for simplicity.