Hi I am a real newbie (hence the delay in replying to this thread) but would really appreciate some help.
I can't get my code to collide with an IBOutlet called UIImageView* lightsabergreenImage;
I think I've confused myself! So how can I get it to collide?
Thanks in advance.
-(void) checkCollision {
for(int i = 0; i<[laserArray i]; i++){
UIImageView* redlaserImage = [laserArray objectAtIndex:i];
if(CGRectIntersectsRect(redlaserImage.frame, lightsabrgreenImage.frame)){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Collision" message:@"the images collide" delegate:self cancelButtonTitle:@"dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(void) accelerometer

UIAccelerometer *)accelerometer didAccelerate

UIAcceleration *)accel
{
float newX = lightsabergreenImage.center.x + (accel.x * 22);
if(newX > 30 && newX < 290) lightsabergreenImage.center = CGPointMake(newX, lightsabergreenImage.center.y);
}
-(void) createLasers
{
if(laserArray == nil) {
laserArray = [[NSMutableArray alloc] init];
}
UIImage *redlaserImage = [UIImage imageNamed:@"redlaser.png"];
myredLaser = [[UIImageView alloc] initWithImage:redlaserImage];
UIImageView *newView;
for(int i = 0; i<1; i++){
newView = [[UIImageView alloc] initWithImage:redlaserImage];
// use the arc4random() function to randomize up our flake attributes
int x = arc4random() % 300;
int y = -arc4random() % 480;
double scale = 1 / round(arc4random() % 100) + 1.0;
double speed = 1 / round(arc4random() % 100) + 1.0;
newView.center = CGPointMake(x, y);
// set the flake start position
newView.frame = CGRectMake(x, -100.0, 18.0 * scale, 50.0 * scale);
newView.alpha = 1.0;
[self.view addSubview:newView];
[laserArray addObject:newView];
[newView release];
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIAccelerometer *theAccel = [UIAccelerometer sharedAccelerometer];
theAccel.updateInterval = 1.0f / 30.0f;
theAccel.delegate = self;
[self.view addSubview:newView];
redlaserImage = [UIImage imageNamed:@"redlaser"];
[NSTimer scheduledTimerWithTimeInterval

0.05) target:self selector:@selector(moveLasers) userInfo:nil repeats:YES];
[self createLasers];
}
-(void) moveLasers {
for(UIImageView* myredLaser in laserArray){
CGPoint newCenter = myredLaser.center;
newCenter.y = newCenter.y + 10; //10 changes the speed
if(newCenter.y > 480){
newCenter.y=0;
newCenter.x = arc4random()%300;
}
myredLaser.center = newCenter;
}
}