ios - 比较两个 CCSprite

标签 ios

_ball = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 52, 52)];
        _ball.position = ccp(300, 300);
        [self addChild:_ball];
_ball1 = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 52, 52)];
        _ball1.position = ccp(300, 300);
        [self addChild:_ball1];


if (_ball1.position.x == _ball.position.x && _ball1.position.y == _ball.position.y) {
        NSLog(@"Stop");
    }

如果球是触球 1 不工作 这里面有什么问题吗?

最佳答案

使用CGRectIntersectsRect确定 Sprite 是否重叠:

if (CGRectIntersectsRect([_ball1 boundingBox], [_ball2 boundingBox])) {
    NSLog(@"Stop");
}

当然,这只是一个矩形的交集,可能不适用于圆形的物体,可以引用这篇webpage中的思路。 .

关于ios - 比较两个 CCSprite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17831507/

相关文章:

ios - 执行 segue 时隐藏键盘转换

ios - 无法加载 wikitude monotouch 绑定(bind)

javascript - 单击时的 window.location.assign 在 iOS 中不起作用

具有自定义 View 的 iOS MVC 实现

ios - 这两个范围相交吗?如果是这样,我怎么知道?

iphone - UILabel 中的 stringWithFormat 和多行文本

ios - 如何以编程方式在 SQLite 中创建多个表,即;通过 ios 中的代码

ios - 如何在swift中为每一行分配不同的颜色

ios - iOS 7 和 iOS 6 中的取消按钮

ios - 如何根据其底部的webview设置Viewcontroller动态高度?