我试图在我的应用程序中使用多点触控....但我必须在手指在屏幕上移动时显示条纹......但我只看到一条而不是两条!我如何创建并移动2条纹?cocos2d多点触控和CCMotionStreak
这里是我的代码:
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (int n=0; n < [allTouches count]; n++)
{
UITouch *touch = [[allTouches allObjects] objectAtIndex:n];
CGPoint touchLoc = [touch locationInNode:self];
streak = [CCMotionStreak streakWithFade:0.3 minSeg:20 width:13 color:[CCColor colorWithUIColor:[UIColor whiteColor]] textureFilename:@"scia.png"];
[streak setPosition:touchLoc];
[self addChild:streak z:30];
}
}
-(void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (int n=0; n < [allTouches count]; n++)
{
UITouch *touch = [[allTouches allObjects] objectAtIndex:n];
CGPoint touchLoc = [touch locationInNode:self];
[streak setPosition:touchLoc];
[self detectObjects:touchLoc];
}
}
我看到你只有一个'sreak'对象,所以你总是将改变应用到该对象...与在数组中的最后一个接触。您可能需要一组条纹,每个触摸一个,并找到将触摸与适当条纹相关联的方式,以便您可以恢复touchMoved中的条纹(可能条纹的userObject属性可能是所涉及的触摸)。 – YvesLeBorg 2014-10-02 14:35:30
确切的说,我正在做不同的测试,但我没有找到如何将触摸与特定的连线相关联... – swifferina 2014-10-02 15:05:58
我没有用过自己,但每个CCNode,因此CCMotionStreak都有一个userObject属性。你可以将它设置为与条纹相关的触摸。在触摸移动,为每个触摸通过你的条纹,直到你找到一个streak.userObject == theTouch; ,然后将该条纹的位置移动到触摸位置。类似的东西。 ymmv :) – YvesLeBorg 2014-10-02 15:08:29