代码之家  ›  专栏  ›  技术社区  ›  user5127227

xcode iOS目标C中的多点触摸

  •  0
  • user5127227  · 技术社区  · 9 年前

    我的游戏中有一个角色,我可以左右移动并跳跃。我用触摸开始做这件事。但当我向左移动(不断触摸屏幕->使角色越来越快)时,它只会在我释放它时跳跃。我想一边跳一边向左移动。

    以下是我的一些代码:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    
    
    if((point.x < moveLeftButton.frame.size.width))
    {
    
        if((point.y > JumpButton.frame.size.height))
        {
            leftSide = YES;
            sanchez.image = [UIImage imageNamed:@"characterL2"];
        }
    
    }
    
    
    if((point.x) > (backGround.frame.size.width - moveRightButton.frame.size.width))
    {
    
        if((point.y > JumpButton.frame.size.height))
        {
            rightSide = YES;
            sanchez.image = [UIImage imageNamed:@"characterR2"];
        }
    
    }
    
    if( notJumping && (point.y < JumpButton.frame.size.height) && (sanchezStopAll == NO))
    {
        AudioServicesPlaySystemSound(jump);
        sanchezJumping = 5.5;
        notJumping = NO;
    
    }
    
    [self animation];
    

    }

    我没有使用buttonPressed,因为它们是隐藏的,我想你不能单击隐藏的按钮。

    如果不隐藏,它的外观如下:

    view 感谢您的帮助。

    1 回复  |  直到 9 年前
        1
  •  1
  •   ChenYilong    9 年前

    默认情况下,除非设置 multipleTouchEnabled = YES 。那么您的代码应该按预期工作。

    例如:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.multipleTouchEnabled = YES;
    }