Objective c 多点触控和CCtouch移动,动作迟缓
我有一个乒乓球游戏,我用手指移动球拍。 只要有一个手指,一切都会顺利进行。但当我想控制两名球员时,两个桨,一个桨动作很好,但另一个桨动作很慢,如果有的话。当第二个桨开始移动时,我的第一个桨冻结了。我如何让这两个动作都感觉平滑和灵敏 我在我的控制器中启用了多点触摸 以下是我的触摸代码:Objective c 多点触控和CCtouch移动,动作迟缓,objective-c,ios,cocos2d-iphone,Objective C,Ios,Cocos2d Iphone,我有一个乒乓球游戏,我用手指移动球拍。 只要有一个手指,一切都会顺利进行。但当我想控制两名球员时,两个桨,一个桨动作很好,但另一个桨动作很慢,如果有的话。当第二个桨开始移动时,我的第一个桨冻结了。我如何让这两个动作都感觉平滑和灵敏 我在我的控制器中启用了多点触摸 以下是我的触摸代码: - (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [touches anyOb
- (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;
}
难道你不应该看你所有的触摸对象而不是抓住任何对象吗?如果您同时移动两个触摸,则只有一个触摸会被移动
- (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;
}
}