繁体   English   中英

如何检测特定NSMutableArray中的对象触摸?

[英]How can I detect a touch of an object in a specific NSMutableArray?

我有一个充满不同精灵的NSMutableArray。 这些精灵都在屏幕上。 我如何检测触摸是否在这些小精灵之一上着陆,如果在小精灵上发生了触摸,该怎么办?

这就是我现在所拥有的

CGPoint touchLocation = [touch locationInNode:_physicsNode];

if(CGRectContainsPoint((starInArray.boundingBox), touchLocation))  {

而不是(starInArray.boundingBox) ,我希望能够说类似(anyObjectInMyArray.boundingBox)

有什么办法吗?

谢谢!

与此类似的东西应该起作用。

  - (BOOL) ccTouchBegan:(UITouch *)touches withEvent:(UIEvent *)event 
{

CGPoint touchLocation = [self convertTouchToNodeSpace:touches];    
        for (CCSprite *star in starInArray)
            {
                if (CGRectContainsPoint(CGRectMake(star.position.x - star.contentSize.width/2,
                                                   star.position.y - star.contentSize.height/2, star.contentSize.width, star.contentSize.height), touchLocation))
                {
                    //Do Something
                    break;
                }
            }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM