我正在使用以下代码绘制线条,它的工作效果令人惊叹,
http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/
现在我想......
1>检测线是否与自身相交.2)检测CCSprite是否在此闭合线内.
在搜索时,我遇到了LineIntersection的许多逻辑,但没有一个是准确的.我给它们中的一个检测交叉点,但是当没有交叉线时它也检测到它.
第一种方法
- (BOOL) lineIntersectOccured:(CGPoint)t1 pointEnd:(CGPoint)t2
{
BOOL result = NO;
int pointsCount = [arrlinePoints count];
CGPoint cp1;
CGPoint cp2;
for(int i = 0, j = 1; j < pointsCount; i++,j++)
{
[[arrlinePoints objectAtIndex:i] getValue:&cp1];
[[arrlinePoints objectAtIndex:j] getValue:&cp2];
// lines connected do not need to be included.
if((cp2.x == t1.x && cp2.y == t1.y) || (cp1.x == t2.x && cp1.y == t2.y))
{
continue;
}
CGPoint diffLA = CGPointMake(cp2.x - cp1.x,cp2.y - cp1.y);
CGPoint diffLB = …Run Code Online (Sandbox Code Playgroud)我有2个单独的项目,一个在Cocos2dx v3.6中,一个在Swift中.我想从Swift项目开始游戏.我该怎么做?
我已将整个cocos2dx项目复制到我的Swift项目中,然后在swift中创建了一个View Controller,并尝试打开CCDirector作为项目的根视图.但是无法找到导演,我试图用#import"cocos2d.h"导入cocos2dx ,但它给了我"未定义文件"的错误.
Apple Swift版本1.2
我有2D数组如下:
NSMutableArray *world=[[NSMutableArray alloc]init];
NSNumber *number;
NSMutableArray *inner;
int scr=2;
number=[[NSNumber alloc]initWithInt:scr];
inner=[[NSMutableArray alloc]initWithObjects:@"ABC",number,nil];
[world addObject:inner];
scr=6;
number=[[NSNumber alloc]initWithInt:scr];
inner=[[NSMutableArray alloc]initWithObjects:@"XYZ",number,nil];
[world addObject:inner];
scr=1;
number=[[NSNumber alloc]initWithInt:scr];
inner=[[NSMutableArray alloc]initWithObjects:@"PQR",number,nil];
[world addObject:inner];
scr=5;
number=[[NSNumber alloc]initWithInt:scr];
inner=[[NSMutableArray alloc]initWithObjects:@"DEF",number,nil];
[world addObject:inner];
scr=3;
number=[[NSNumber alloc]initWithInt:scr];
inner=[[NSMutableArray alloc]initWithObjects:@"LMN",number,nil];
[world addObject:inner];
Run Code Online (Sandbox Code Playgroud)
现在,我想对world数组进行排序以获得以下结果,
XYZ 6
DEF 5
LMN 3
ABC 2
PQR 1
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我,提前谢谢...