好吧,我最后一次尝试了这个,它太模糊,所以我会再试一次。我正在制作一个自上而下的透视iPhone游戏,有一个mainSprite(一个UIImageView),它将与另一个UIImageView相冲突。当它发生时,我希望mainSprite停止移动。基本上创造一堵墙。那有意义吗?我没有使用任何框架,如cocos2d。我知道CGRectIntersectWithRect方法,我的问题是我需要在该方法中放置什么。我没有任何其他变量,例如速度或速度,只是会在屏幕上移动精灵的按钮。这是我的代码。iPhone游戏开发,碰撞检测,创造了墙效应
这是用于在屏幕上移动精灵的.m代码。
-(void)goDown{
mainSprite.center = CGPointMake(mainSprite.center.x, mainSprite.center.y+5);
}
-(IBAction)down{
[self downAnimation];
goDown = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
if (goDown == nil) {
goUp = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
}
}
这里是我已建立了碰撞的方法:
-(void)collision {
if (CGRectIntersectsRect(mainSprite.frame, collisionImage.frame)) {
}
}
帮助将不胜感激。
这很有道理,但你能告诉我如何重置mainSprite位置到其他UIImageView之外吗? –
你的意思是在另一个之外? – DanZimm
就像mainSprite与UIImageView相撞时,我需要写什么代码才能将mainSprite保留在UIImageView之外,从而创建墙效果? –