【问题标题】:Assigning collision properties to layers on Tiled and using them in Cocos2D将碰撞属性分配给 Tiled 上的图层并在 Cocos2D 中使用它们
【发布时间】:2011-04-06 17:31:51
【问题描述】:

我最近关注了一个关于在 Cocos2D 中使用 tmx 文件在 tiled 中创建碰撞检测的教程:http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2

虽然这对我来说非常有用,但我还希望能够检测整个图层上图块的碰撞属性,而不仅仅是检测单个图块上的碰撞属性。

我在 Tiled 上注意到,您可以右键单击图层并分配属性,就像使用单个图块一样。

在我的代码中的一个方法中,我有一种检查图块属性的方法:

CGPoint tileCoord = [self tileCoordForPosition:position];

int tileGid = [invisiblePropertiesLayer tileGIDAt:tileCoord];

if(tileGid){
    NSDictionary *properties = [theMap propertiesForGID:tileGid];

    if(properties){
        NSString *collision = [properties valueForKey:@"collidable"];
        if(collision && [collision compare:@"true"] == NSOrderedSame) {
            return;
        }
    }
}

有没有办法可以更改它以检查我是否与特定图层上的任何图块发生碰撞?谢谢!

【问题讨论】:

    标签: iphone cocos2d-iphone collision-detection layer


    【解决方案1】:

    其他人在另一个论坛上告诉我如何做到这一点。就这么简单:

        CGPoint tileCoord = [self tileCoordForPosition:position];
    
    int tileGid = [blocksCollidable tileGIDAt:tileCoord];
    
    if (tileGid)
        return;
    

    【讨论】:

      猜你喜欢
      • 2016-03-16
      • 2018-04-25
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2013-12-29
      • 1970-01-01
      相关资源
      最近更新 更多