0
權基本上是什麼香港專業教育學院得到的是一個應用程序,它是一個球和球棒,其可以有多少反彈實現,它工作正常的,但有一個問題,IPhone SDK幫助的小遊戲
當球擊中邊蝙蝠的它拋出它偏離軌道和它的像球的框架中的蝙蝠框架反彈,這是我的代碼在我mainview.m
#import "MainView.h"
#define kGameStateRunning 1
@implementation MainView
@synthesize paddle, ball;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
CGPoint xLocation = CGPointMake(location.x,paddle.center.y);
paddle.center = xLocation;
}
-(IBAction) play {
pos = CGPointMake(14.0,7.0);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
-(void) onTimer {
ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);
if(ball.center.x > 320 || ball.center.x < 0)
pos.x = -pos.x;
if(ball.center.y > 460 || ball.center.y < 0)
pos.y = -pos.y;
[self checkCollision];
}
-(void) checkCollision {
if(CGRectIntersectsRect(ball.frame,paddle.frame)) {
pos.y = -pos.y;
}
}
@end
任何人都可以在這裏工作出了問題? 謝謝 哈利