我有一个乒乓球比赛,我用手指移动球拍。 当有一根手指时,这一切都很顺利。但是当我想要控制两个球员,两个桨,一个桨移动很好但另一个桨移动非常迟钝,如果有的话。当第二个桨叶开始移动时,我的第一个桨叶冻结。如何使两个动作都感觉平稳和反应灵敏?
我的导演已启用多点触控功能。
这是我的触摸代码:
- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CGRect leftTouchZone = CGRectMake(0, 0, 50, 320);
CGRect rightTouchZone = CGRectMake(430, 0, 50, 320);
if (CGRectContainsPoint(leftTouchZone, location))
{
CGPoint tempLoc = location;
tempLoc.x = paddle1.position.x;
paddle1.position = tempLoc;
}
if (CGRectContainsPoint(rightTouchZone, location))
{
CGPoint tempLoc = location;
tempLoc.x = paddle2.position.x;
paddle2.position = tempLoc;
}
答案 0 :(得分:1)
你不应该浏览所有的触摸物体而不是仅仅抓住物体吗?如果您同时移动2个触摸,则只有一个触摸移动事件。
- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch* myTouch in touches)
{
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
CGRect leftTouchZone = CGRectMake(0, 0, 50, 320);
CGRect rightTouchZone = CGRectMake(430, 0, 50, 320);
if (CGRectContainsPoint(leftTouchZone, location))
{
CGPoint tempLoc = location;
tempLoc.x = paddle1.position.x;
paddle1.position = tempLoc;
}
if (CGRectContainsPoint(rightTouchZone, location))
{
CGPoint tempLoc = location;
tempLoc.x = paddle2.position.x;
paddle2.position = tempLoc;
}
}