【问题标题】:How to add multiple touch locations with multiple bounding boxes?如何使用多个边界框添加多个触摸位置?
【发布时间】:2014-08-16 18:01:45
【问题描述】:

我在屏幕上有两个 CCSprite。一个叫_star,另一个叫_redStar。

它说CGRectContainsPoint,我怎么能说像_star.boundingBox OR _redstar.boundingBox,touchLocation。我不确定这是否可行,如果可以,我只是不知道语法。任何帮助将不胜感激!

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

        CGPoint touchLocation = [touch locationInNode:_physicsNode];

        if(CGRectContainsPoint((_star.boundingBox), touchLocation)) 

【问题讨论】:

    标签: objective-c xcode cocos2d-iphone game-physics


    【解决方案1】:

    这是一个非常简单的编程任务。您使用 ||喜欢:

    - (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
    {
        CGPoint touchLocation = [touch locationInNode:_physicsNode];
    
        if(CGRectContainsPoint(_star.boundingBox, touchLocation) ||
           CGRectContainsPoint(_redstar.boundingBox, touchLocation))
        {
            // Do something
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      相关资源
      最近更新 更多