Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphonesdk小游戏帮助_Iphone - Fatal编程技术网

iphonesdk小游戏帮助

iphonesdk小游戏帮助,iphone,Iphone,好的,基本上我得到的是一个应用程序,它是一个球和球拍,它能实现多少反弹,它工作正常,但有一个问题 当球击中球棒的侧面时,它会将球抛出球场,就像球的框架在球棒的框架中反弹一样,这是我在mainview中的代码 #import "MainView.h" #define kGameStateRunning 1 @implementation MainView @synthesize paddle, ball; - (void)touchesMoved:(NSSet *)touches withEv

好的,基本上我得到的是一个应用程序,它是一个球和球拍,它能实现多少反弹,它工作正常,但有一个问题

当球击中球棒的侧面时,它会将球抛出球场,就像球的框架在球棒的框架中反弹一样,这是我在mainview中的代码

#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
#导入“MainView.h”
#定义kGameStateRunning 1
@实现主视图
@综合桨、球;
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[touch locationInView:touch.view];
CGPoint xLocation=CGPointMake(位置.x,桨叶中心.y);
桨叶中心=X位置;
}
-(i)玩{
pos=CGPointMake(14.0,7.0);
[NSTimer scheduledTimerWithTimeInterval:0.05目标:自选择器:@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;
[自我检查碰撞];
}
-(无效)检查碰撞{
if(CGRECT(球架、桨架)){
pos.y=-pos.y;
}
}
@结束
有人能解决这个问题吗? 谢谢
Harry

您正在测试矩形相交,也许您应该做一个圆碰撞

Distance(C1, C2) <= R1 + R2 means that the circles collided
距离(C1、C2)