我正在开发一个生成图像的项目,您基本上触摸它们并将它们删除。我将如何移除我触摸的对象?我曾想过制作一个可变数组来保存所有对象,但我似乎无法弄清楚任何事情。
GameViewController.m
#import "GameViewController.h"
#import "Cig.h"
@interface GameViewController ()
@end
@implementation GameViewController
@synthesize scoreLbl, timeLbl;
//CLASS ONLY VARS
BOOL isGameOver;
int timeInt;
int scoreInt;
int cigsOnScreen;
NSMutableArray *spawnedCigs;
//CLASS ONLY VARS
//TIMER
-(void)count {
timeInt--;
timeLbl.text = [NSString stringWithFormat:@"Time: %i", timeInt];
if(timeInt == 0){
isGameOver = YES;
NSLog(@"Your Score For This Round: %i", scoreInt);
}
if(isGameOver == NO){
[self performSelector:@selector(count) withObject:nil afterDelay:1];
}
}
//TIMER
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)spawnCigs {
for(int i =0 ; i < 5; i++){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(arc4random()%760, arc4random()%430, 100, 23)];
UIImage *image = [UIImage imageNamed:@"Cig.png"];
[imageView setImage:image];
Cig *cig = [[Cig alloc] init];
[cig setTag:arc4random()%666];
[cig setImage:imageView];
[spawnedCigs addObject:cig];
[self.view addSubview:imageView];
}
[self performSelector:@selector(spawnCigs) withObject:nil afterDelay:5];
}
-(void)reset {
scoreLbl.text = @"Score:";
timeLbl.text = @"Time:";
isGameOver = NO;
timeInt = 60;
scoreInt = 0;
cigsOnScreen = 0;
spawnedCigs = [NSMutableArray arrayWithObjects:nil, nil];
[self performSelector:@selector(count) withObject:nil afterDelay:1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self reset];
[self spawnCigs];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
代码非常混乱,所以请不要以此评判我。
感谢您提供的任何帮助