Note that there are some explanatory texts on larger screens.

plurals
  1. POAction in collision detection (CGRectIntersectsRect)
    primarykey
    data
    text
    <p>I have two images. You have to use a <code>acceleremoter</code> to move a man and avoid a big spike. Here is my .h coding:</p> <pre><code>IBOutlet UIImageView *rect1; IBOutlet UIImageView *rect2; </code></pre> <p>Here is my .m:</p> <pre><code>bool CGRectIntersectsRect ( CGRect rect1, CGRect rect2 ); </code></pre> <p>I have connected everything in the nib file and I know nothing would happen because there was no error. I need these two things to collide and then generate an end screen. BUT <em>HOW</em> do I put an action in. THANKS!</p> <p>.m</p> <pre><code>#import "GameScreen.h" @implementation GameScreen @synthesize ball, delta; -(void)viewDidLoad { UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer]; accel.delegate = self; accel.updateInterval = 1.0f / 60.0f; [super viewDidLoad]; } -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { NSLog(@"x : %g", acceleration.x); NSLog(@"y : %g", acceleration.y); NSLog(@"z : %g", acceleration.z); delta.y = acceleration.y * 70; delta.x = acceleration.x * 70; ball.center = CGPointMake(ball.center.x + delta.x, ball.center.y + delta.y); // Right if(ball.center.x &lt; 0) { ball.center = CGPointMake(320, ball.center.y); } // Left if(ball.center.x &gt; 320) { ball.center = CGPointMake(0, ball.center.y); } // Top if(ball.center.y &lt; 0) { ball.center = CGPointMake(ball.center.x, 460); } // Bottom if(ball.center.y &gt; 460){ ball.center = CGPointMake(ball.center.x, 0); } } bool CGRectIntersectsRect ( CGRect rect1, CGRect rect2 ); -(void)dealloc { [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload