CGPath is not detected properly in cocos2d(cocos2d中没有正确检测到CGPath)
问题描述
通过帮助和建议,我为我的精灵创建了一条路径,以便只能触摸不透明的部分.这是我想出的路径:
Through help and suggestions, I created a path for my sprite so that only the non-transparent parts can be touched. This is the path I came up with:
path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, endTouch.x, endTouch.y);
CGPathAddLineToPoint(path, NULL, 0, 250);
CGPathAddLineToPoint(path, NULL, 30, 0);
CGPathCloseSubpath(path);
这适用于我的所有其他课程,除了一个.无论我在哪里点击,xcode 都会使用此代码在外部"打印:
This works for all my other classes except for one. No matter where I tap, xcode keeps printing "outside" using this code:
for(int i = 0; i < [sprArray count]; i++)
{
CCSprite *sprite = (CCSprite *)[sprArray objectAtIndex:i];
if(CGRectContainsPoint([sprite boundingBox], location))
{
selectedSprite = sprite;
location = [selectedSprite convertToNodeSpace:location];
if (CGPathContainsPoint(path, NULL, location, NO) )
{
NSLog(@"inside");
}
else
{
NSLog(@"outside");
}
break;
}
}
如果我进入 if 条件,我只能移动我的精灵,否则,即使我点击实际的彩色精灵,它也不会得到我设置的路径.我的测量值有误吗?如果没有,我做错了什么?这与我尝试使用的图像相似...
I can only move my sprites if I get inside the if-condition, not else but even if I tap on the actual, colored sprite, it doesn't get the path I set. Are my measurements wrong? If not, what am I doing wrong? This is similar to the image I'm trying to use...
推荐答案
这仅适用于图像大小相同的情况.根据图像大小计算坐标.
This works only if image size is same. Depending on image size calculate coordinates.
CGPathMoveToPoint(path, NULL, 54, 0 ); //1: 54 = distance from left, 0 = dis fem bottom
CGPathAddLineToPoint(path, NULL, 28, 34 );
CGPathAddLineToPoint(path, NULL, 36, 76 );
CGPathAddLineToPoint(path, NULL, 51, 104 );
CGPathAddLineToPoint(path, NULL, 46, 147 );
CGPathAddLineToPoint(path, NULL, 67, 147 );
CGPathAddLineToPoint(path, NULL, 70, 105 );
CGPathAddLineToPoint(path, NULL, 56, 66 );
CGPathAddLineToPoint(path, NULL, 52, 42 );
CGPathAddLineToPoint(path, NULL, 67, 20 );
CGPathAddLineToPoint(path, NULL, 92, 0 );
CGPathCloseSubpath(path);
这篇关于cocos2d中没有正确检测到CGPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cocos2d中没有正确检测到CGPath
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01