【问题标题】:determine if a sprite is on screen or not in cocos2d在 cocos2d 中确定精灵是否在屏幕上
【发布时间】:2011-11-06 06:01:27
【问题描述】:

我想确定精灵是否在屏幕中或不在 cocos2d 中。

我正在使用类似这样的代码。

CGSize winSize = [CCDirector sharedDirector].winSize;

    if (_SmallBlueAlien1.position.x> 0 || _SmallBlueAlien1.position.x > winSize.width || _SmallBlueAlien1.position.y> 0 || _SmallBlueAlien1.position.y > winSize.height)
    {
//Sprite is not in the screen)
}

但无法正常工作。我错了。 纠正我

【问题讨论】:

    标签: iphone objective-c xcode4 cocos2d-iphone


    【解决方案1】:

    除非你改变了精灵的锚点,否则这只是测试精灵的一半是否在屏幕上。要解决此问题,您需要检查是否

    _SmallBlueAlien1.position.x > [_SmallBlueAlien1 contentSize].texture.width / 2;

    您可以按照此流程进行所有其他交互。

    //编辑

    正如 phix23 所指出的,这不考虑旋转或缩放,但如果你不做这些,应该可以工作。

    【讨论】:

    • 你还应该考虑缩放和旋转
    • 纹理出现错误“没有名为“纹理”的成员”
    • @Srinivas 你可以做 [_SmallBlueAlien1 contentSize].width / 2
    【解决方案2】:

    不管 coco 中 'position' 的语义如何,假设您对 .position 属性的解释成立,您的 x 和 y 的 '>' 都应该是 '

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      相关资源
      最近更新 更多