gpt4 book ai didi

objective-c - 多点触控和 ccTouchesMoved,移动滞后

转载 作者:行者123 更新时间:2023-11-29 04:30:23 25 4
gpt4 key购买 nike

我有一个乒乓球游戏,我用手指来移动 Racket 。只要有一根手指,一切都会顺利进行。但是,当我想控制两个玩家、两个 Racket 时,一个 Racket 移动得很好,但另一个 Racket 移动得很慢(如果有的话)。当第二个桨开始移动时,我的第一个桨卡住了。如何使这两种 Action 感觉流畅且 react 灵敏?

我在 Director 中启用了多点触控。

这是我的触摸代码:

- (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;
}

最佳答案

您不应该查看所有触摸的对象,而不是仅仅捕获任何对象吗?如果您同时移动 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;
}
}

关于objective-c - 多点触控和 ccTouchesMoved,移动滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11815205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com