ボールを別のボールから遠ざける必要がある単純なゲームアプリを構築しています。ただし、コードに問題があります。助けてください。ビルドして実行すると、2 つのエラー メッセージが表示されます。何が問題なのかわかりません。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//(X speed, Y speed) vvv
pos = CGPointMake(5.0,4.0);///////// this part here I get an error message saying assigning to CGPoint * (aka 'struct CGPoint*') from incompatible type 'CGPoint' (aka 'struct CGPoint')
}
- (IBAction)start {
[startbutton setHidden:YES];
randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.03) target:(self) selector:@selector(onTimer) userInfo:nil repeats:YES];
}
-(void)onTimer {
[self checkCollision];
enemy.center = CGPointMake(enemy.center.x+pos->x,enemy.center.y+pos->y);
if (enemy.center.x > 320 || enemy.center.x < 0)
pos->x = -pos->x;
if (enemy.center.y > 480 || enemy.center.y < 0)
pos->y = -pos->y;
}
-(void)checkCollision {
if( CGRectIntersectsRect(player.frame,enemy.frame))
{
[randomMain invalidate];
[startbutton setHidden:NO];
CGRect frame = [player frame];
frame.origin.x = 137.0f;
frame.origin.y = 326.0;
[player setFrame:frame];
CGRect frame2 = [enemy frame];
frame2.origin.x =137.0f;
frame2.origin.y = 20.0;
[enemy setFrame:frame2];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You Lost!" message:[NSString stringWithFormat:@"You Were Hit! Try Again"] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(void)touchesMoved: (NSSet *)touches withEvent: (UIEvent *)event {
UITouch *myTOuch = [[event allTouches] anyObject];
player.center = [myTouch locationInView:self.view]; /////// Here also I get an error message saying Assigning to 'CGPoint' (aka struct CGPoint') form incompatible type 'id'
////////////////// Also with that error message is Class method '+locationalView' not found (return type defaults to 'id')
}
@end