У меня есть два изображения. Вы должны использовать acceleremoter
, чтобы двигать человека и избегать большого скачка. Вот моя кодировка .h:
IBOutlet UIImageView *rect1;
IBOutlet UIImageView *rect2;
Вот мой .m:
bool CGRectIntersectsRect ( CGRect rect1, CGRect rect2 );
Я подключил все в nib-файле и знаю, что ничего не произойдет, потому что ошибки не было. Мне нужно, чтобы эти две вещи столкнулись, а затем создали конечный экран. НО КАК сделать действие. СПАСИБО!
.m
#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 < 0) {
ball.center = CGPointMake(320, ball.center.y);
}
// Left
if(ball.center.x > 320) {
ball.center = CGPointMake(0, ball.center.y);
}
// Top
if(ball.center.y < 0) {
ball.center = CGPointMake(ball.center.x, 460);
}
// Bottom
if(ball.center.y > 460){
ball.center = CGPointMake(ball.center.x, 0);
}
}
bool CGRectIntersectsRect ( CGRect rect1, CGRect rect2 );
-(void)dealloc {
[super dealloc];
}
@end