0

So I want to divide my game into chunks by using several different CCTMXTiledMaps. I am able to load the maps into my main 'HelloWorldLayer'. I am also able to detect whether the player sprite collides with a tile with the property of 'collectable'. My problem occurs when I add several CCTMXTiledMap nodes to the game, as it doesn't do the collectible tile detection on all of them, just the first one.

Here is my working code that does the check, but only for the first added CCTMXTledMap:

    CGPoint point = [self getTileCoordForPosition:position :map];

    CCTMXLayer *metaLayer = [map layerNamed:@"Meta"];
    CCTMXLayer *foregroundLayer = [map layerNamed:@"Foreground"];
    CCSprite *metaTile = [metaLayer tileAt:point];
    CCSprite *foregroundTile = [foregroundLayer tileAt:point];

    if (foregroundTile)
    {
        NSLog(@"HIT!");

        // Remove the meta tile and the foreground tile
        [metaLayer removeTileAt:point];
        [foregroundLayer removeTileAt:point];
    }

How can I make this code do the check for every CCTMXTiledMap node that has been added?

Sneaksta
  • 1,041
  • 4
  • 24
  • 46
  • I am working on tile map for last two months,So my first question to you? Do you able to load all the tile maps? If yes then please show more descriptive code of your. So that i will understand the problem properly. – Renaissance Jun 25 '13 at 13:00
  • Check map's position and find map which is inside the game and check collision on same. Here is sample game http://stackoverflow.com/questions/12345556/cocos2d-continuously-scrolling-tile-based-game-strange-flash-only-in-device – Guru Jun 26 '13 at 05:32

1 Answers1

0

The problem was that I was calculating the tile map positions wrong, in a tile map co-ordinates to map position function.

I was multiplying by the CC_SCALE_RATIO() function, or something like that (going off the top of my head), and it was mis-calculating the pixel positioning.

Just thought I'd write in an answer since I found the solution. Hope it helps somebody!

Sneaksta
  • 1,041
  • 4
  • 24
  • 46