iOS游戏-矢量碰撞
我正在为iOS制作一个游戏。我输入了两个图像,一个用作播放器,另一个用作对象。我想编写代码,如果两个对象相交,那么它将运行方法EndGame 虽然图像不是正方形,但UIImage是正方形。因此,当两个物体相交时,游戏结束,即使两个图像看起来很接近,但由于碰撞检测不正确,游戏仍然结束。你有什么建议吗 我可以在XCODE上更改图像形状吗?如果图像与玩家图像上的某个点发生碰撞,我可以这样做吗iOS游戏-矢量碰撞,ios,objective-c,xcode,uiimageview,collision-detection,Ios,Objective C,Xcode,Uiimageview,Collision Detection,我正在为iOS制作一个游戏。我输入了两个图像,一个用作播放器,另一个用作对象。我想编写代码,如果两个对象相交,那么它将运行方法EndGame 虽然图像不是正方形,但UIImage是正方形。因此,当两个物体相交时,游戏结束,即使两个图像看起来很接近,但由于碰撞检测不正确,游戏仍然结束。你有什么建议吗 我可以在XCODE上更改图像形状吗?如果图像与玩家图像上的某个点发生碰撞,我可以这样做吗 谢谢。创建自定义视图,并在draw rect中创建贝塞尔路径。像这样的 UIBezierPath *path
谢谢。创建自定义视图,并在draw rect中创建贝塞尔路径。像这样的
UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:ball.center radius:ballRadius startAngle:0.0 endAngle:M_PI*2.0 clockwise:YES];
这将绘制一个圆形视图
编辑:这里有一个例子-我不确定所有的细节是什么,所以这是相当一般的
@interface ballView : UIView//create subclass of UIView
。。。
@实施
- (void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];//create bezier path
[path addArcWithCenter:self.center radius:5.0 startAngle:0.0 endAngle:M_PI*2.0 clockwise:YES];//draw circle. You can change around the parameters to the way you like
[[UIColor orangeColor]setStroke];
[path stroke];//draw line
我将如何创建自定义视图,以及如何在同一方法中包含该代码?完成此操作后,如何将新的rect添加到碰撞方法中?与创建Ball.frame的方法相同。这是UIView谢谢,但是UIColor和orangeColor是什么?只是设置线条的颜色。如果你想的话,把那条线拿出来。
- (void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];//create bezier path
[path addArcWithCenter:self.center radius:5.0 startAngle:0.0 endAngle:M_PI*2.0 clockwise:YES];//draw circle. You can change around the parameters to the way you like
[[UIColor orangeColor]setStroke];
[path stroke];//draw line