- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
////////////
sound code
NSString * path = [[NSBundle mainBundle] pathForResource:@"ballhitbar" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
and to play wrte this
AudioServicesPlaySystemSound(soundID);
///////////////////////////////////// random
//Here is the spawnE...
-(void)spawnE {
enemies = [[NSMutableArray alloc] init];
UIImage *enemyImage = [UIImage imageNamed:@"enemy.png"];
UIImageView *newEnemy = [[UIImageView alloc] initWithImage: enemyImage];
int randomX = arc4random() % 320; // number from 0 to 319
newEnemy.center = CGPointMake( randomX, 0);
[enemies addObject:newEnemy];
[self addSubview: newEnemy];
}
///////// or
enemies = [[NSMutableArray alloc] init];
UIImage *enemyImage = [UIImage imageNamed:@"bug.png"];
for (int i=0; i<12; i++){
newEnemy = [[UIImageView alloc] initWithImage: enemyImage];
int randomX = arc4random() % 320; // number from 0 to 319
int randomY = arc4random() % 480;
newEnemy.center = CGPointMake( randomX,randomY);// working all over screen
[enemies addObject:newEnemy];
[self addSubview: newEnemy];
//newEnemy.userInteractionEnabled = YES;
}
//[self move];
}
//////////////
No comments:
Post a Comment