gpt4 book ai didi

iphone - 无法使用 touchesMoved 同时拖动 2 个 imageView

转载 作者:行者123 更新时间:2023-11-29 13:44:55 25 4
gpt4 key购买 nike

我正在制作乒乓球游戏,当我作为 2 个玩家玩时,图像不会同时移动:我必须释放一个才能移动另一个。

代码如下:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self touchesMoved:touches withEvent:event];
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];

if (location.x > 240) {
CGPoint ylocation = CGPointMake(player.center.x, location.y);
player.center = ylocation;

}
if (mode == kdual) {
if (location.x < 240) {
CGPoint ylocation = CGPointMake(cpu.center.x, location.y);
cpu.center = ylocation;
}
}
}

最佳答案

您只检查一个触摸对象的位置。您应该检查所有触摸对象,并相应地移动图像。像这样:

for (UITouch * touch in [touches allObjects])
{
// Check position of touch and move the images
CGPoint location = [touch locationInView:touch.view];

if (location.x > 240) {
CGPoint ylocation = CGPointMake(player.center.x, location.y);
player.center = ylocation;

}
if (mode == kdual) {
if (location.x < 240) {
CGPoint ylocation = CGPointMake(cpu.center.x, location.y);
cpu.center = ylocation;
}
}
}

关于iphone - 无法使用 touchesMoved 同时拖动 2 个 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7767885/

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