Collisions With Falling Images Not Working? HELP!

Discussion in 'Public Game Developers Forum' started by willevansapps, Jan 28, 2011.

  1. willevansapps

    willevansapps Well-Known Member

    Apr 24, 2010
    100
    0
    0
    iPhone App Developer
    UK
    Ok, well I have the code to make an ImageView fall down the screen and then also the code for a collision to take place if they hit. Now my problems are:

    a) How to make the image repeatably drop down at intervals
    b) How to get the collision working to display a UIAlertView.

    Ok the codes are:

    Viewdidload set timer:

    Code:
    - (void)viewDidLoad {
    	
    	[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0/30.0];
    	[[UIAccelerometer sharedAccelerometer] setDelegate:self]; [super viewDidLoad];
    	moveEnemyTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (moveEnemy) userInfo:nil repeats:YES];
    }
    
    MoveEnemy Void:

    Code:
    - (void) moveEnemy {
    	
    	enemy.center = CGPointMake(enemy.center.x , enemy.center.y +10);
    	
    }
    
    Check Collision Void:

    Code:
    - (void)checkcollision {
    	
    	if (CGRectIntersectsRect(enemy.frame, ball.frame)) {
    		
    		UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
    		// optional - add more buttons:
    		[alert addButtonWithTitle:@"Yes"];
    		[alert show];
    	}
    }
    
    Header File:

    Code:
    @interface Aliens_Go_BoomViewController : UIViewController <UIAccelerometerDelegate> {
    	
    	IBOutlet UIImageView *ball;
    	IBOutlet UIImageView *enemy;
    	
    	
    	NSTimer *moveEnemyTimer;
    	
    	float valueX;
    	float valueY;
    
    }
    
    @property (nonatomic, retain) UIImageView *enemy;
    @property (nonatomic, retain) UIImageView *ball;
    
    All the ImageViews are linked up. But the AlertView just isn't displaying. Also how would I repeatedly drop the image every * seconds?

    Thanks!
     

Share This Page