How collision map? I have call:

// Get TMX Map and associated layers/groups
_map = CCTMXTiledMap.tiledMap("mapdemo.tmx");
_background = _map.layerNamed("Background");
_objects = _map.objectGroupNamed("Objects");

people can help me. check character when collision _object.

  • \$\begingroup\$ You'll need to be more specific so that someone can help you. \$\endgroup\$ – Vaughan Hilts May 12 '15 at 4:43

There is a tutorial HERE that will help you using Tiled Map to create collisions as you are using this technology. Basically, if you are using Tiled Map you will mostly do Pathfinding, when you calculate the closest path to move to X,Y position, you need to check if this path contains some "collider" tiles, using a method like:

-(BOOL) isCollisioning:(CGPoint) position{
    CGPoint tileCoord = [self tileCoordForPosition:position];
    int tileGid = [_meta tileGIDAt:tileCoord];
    if (tileGid) {    
        NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
        if (properties) {        
            NSString *collision = properties[@"Collidable"];
            if (collision && [collision isEqualToString:@"True"]) {            
               return true;
   return false;

So the tile is not really a physical body, but you will not be able to go inside it. Of course, it means you have prepared your Tilemap accordingly (link explains how to with a step by step).

If you wanted to make each of the squares collidable, which I don't recommend for performance and complexity issues, you will have to use an external library (for example Box2D) and create a phyisic body for each collidable tile in your tilemap (of course you should try to make bigger physic bodies if you have them together, to improve performance).

  • \$\begingroup\$ Please don't post link-only answers. Please read the help center for more details about good answers. \$\endgroup\$ – bummzack May 13 '15 at 11:20
  • \$\begingroup\$ Edited to improve the answer! \$\endgroup\$ – aramusss May 13 '15 at 14:35
  • \$\begingroup\$ sorry, i write java and lib is: cocos2d-android. you train to java help me. thank \$\endgroup\$ – QuestionAndroid May 14 '15 at 2:37
  • \$\begingroup\$ I am not a Java expert, but i hope this helps: [object method:parameter] in Objective C is the same as object.method(parameter) in Java. NSDictionary would be a Map<object, object> (that are the properties that you should have in your tilemap, created same way the tutorial in the link shows you). Any question just ask! \$\endgroup\$ – aramusss May 14 '15 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.