1
votes

My desired usage is this:

  1. Create a .tmx map using Tiled that specifies the background and the starting location of a bunch of what will become PhysicsBody objects in SpriteKit
  2. Use JSTileMap to read the .tmx and display it
  3. Within the tilemap object that JSTileMap makes, reference the appropriate layers/objects/whatever to turn into various PhysicsBody objects, whose position is now controlled by the physics engine

I've successfully done 1. and 2. above but I'm stuck on 3. I can reference a layer or object, but when I even try a simple test to change its position (using the setPosition method), it crashes.

I'm very open to using something other than JSTileMap if that would make the ultimate goal of getting manipulatable layers/objects from a .tmx easier.

2

2 Answers

6
votes

I'm the maintainer of JSTileMap. I have a sample project I did about a month ago that has some examples of what you're talking about here. You are welcome to have a look at my code: https://dl.dropboxusercontent.com/u/14626689/Platformer%20Test%201.zip

It should give you most of the answers you are looking for as well as having some slight tweaks to JSTileMap that are as yet unpublished.

1
votes

Based on the sample project that slycrel provided, it looks like this is the code snippet relevant to address my question:

TMXLayerInfo* layerInfo = [self.tileMap.layers firstObject];
        CGPoint pt = CGPointMake(a, b);
        NSInteger gid = [layerInfo.layer tileGidAt:[layerInfo.layer pointForCoord:pt]];
        if (gid == 2)
        {
            SKSpriteNode* node = [layerInfo.layer tileAtCoord:pt];
            node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:node.frame.size];
            node.physicsBody.dynamic = NO;
        }

Unfortunately, it looks like something is wrong with the gids. _gid_data is nil. currentFirstGID shows up as 0. I'm not sure what I'm doing wrong.