[plugin] rex_tmx_importer_v2

Post your completed addons to share with the community

Post » Fri Mar 24, 2017 7:08 pm

faulknermano wrote:@digitalsoapbox
Rex PM'd me about a TMX Importer V2 update but it seems he had forgotten to update this thread.

Here's a direct quote from @rexrainbow
rexrainbow wrote:Please update tmx related plugins.

Add new expression:ObjectRefGID to get reference gid of an object, and extend expression:TilesetName( gid ) to get tileset name of a specific tile (gid).
ex : TMXImporterV2.TilesetName( TMXImporterV2.ObjectRefGID )
Hereis a sample capx.



The 'gid' is what you're looking for. It's basically the 'frame number' of the Object, as it were.

I also believe that Rex updated only the one in his main site, not the Github one, last I checked.


@faulknermano @rexrainbow
Thanks! I'll poke around with it and see if I can get it working.

This works to set the animation, but what do I need to do to set the animation frame? I'm getting the right tileset name to reference for setting the animation from TMXImporterV2.TilesetName( TMXImporterV2.ObjectRefGID ), but not a tile ID to reference as frame number.
B
80
S
46
G
24
Posts: 525
Reputation: 20,955

Post » Fri Mar 24, 2017 9:20 pm

@digitalsoapbox

I see the issue. The ObjectRefGID is the raw value, but in order to extract the frame ID, the plugin also needs the 'firstgid' parameter from the Tileset because the frame number is relative to the tileset being used. IE: frameNumber=TilesetFirstGID-ObjectRefGID.

As the plugin currently stands I think @rexrainbow might need to add the retrieval of the Tileset's 'firstgid' parameter in order to extrapolate the frame number. Sorry for getting your hopes up, but hopefully, Rex will pipe up. :-)

In the meantime, Bjorn, the Tiled developer (am I right in assuming you are using Tiled), doesn't recommend using Tile IDs to reference tiles in a tileset because they are 'volatile'. I had to agree with him because I found out in my situation, I could not reset certain tiles to start at 0 within Tiled. For example, in one of my tilesets, the first tile's id is 3, and there are some the skipped a number. And so referencing them in C2 was yielding incorrect frames even though the tile ordering was identical.

The only practical solution for me was to apply a custom property to each individual tile assigning them a frame number. I think this a much better solution as it is predictable. Also, it is also possible to parse the TMX externally that will procedurally make the correspondence between the TMX tileset and the animation frames in C2.

Lastly, I have modified Rex's code specifically for this 'Image Object Tile ID' requirement, but I have not requested Rex to 'pull' my modifications as I think it's better for Rex to maintain his plugins. If Rex allows me to post modifications to his code then I'll do that here.

But again, I personally have abandoned the idea of using Tile IDs for frame numbers mainly because they're not dependable.
B
41
S
12
G
1
Posts: 69
Reputation: 2,957

Post » Fri Mar 24, 2017 10:09 pm

faulknermano wrote:@digitalsoapbox

I see the issue. The ObjectRefGID is the raw value, but in order to extract the frame ID, the plugin also needs the 'firstgid' parameter from the Tileset because the frame number is relative to the tileset being used. IE: frameNumber=TilesetFirstGID-ObjectRefGID.

As the plugin currently stands I think @rexrainbow might need to add the retrieval of the Tileset's 'firstgid' parameter in order to extrapolate the frame number. Sorry for getting your hopes up, but hopefully, Rex will pipe up. :-)

In the meantime, Bjorn, the Tiled developer (am I right in assuming you are using Tiled), doesn't recommend using Tile IDs to reference tiles in a tileset because they are 'volatile'. I had to agree with him because I found out in my situation, I could not reset certain tiles to start at 0 within Tiled. For example, in one of my tilesets, the first tile's id is 3, and there are some the skipped a number. And so referencing them in C2 was yielding incorrect frames even though the tile ordering was identical.

The only practical solution for me was to apply a custom property to each individual tile assigning them a frame number. I think this a much better solution as it is predictable. Also, it is also possible to parse the TMX externally that will procedurally make the correspondence between the TMX tileset and the animation frames in C2.

Lastly, I have modified Rex's code specifically for this 'Image Object Tile ID' requirement, but I have not requested Rex to 'pull' my modifications as I think it's better for Rex to maintain his plugins. If Rex allows me to post modifications to his code then I'll do that here.

But again, I personally have abandoned the idea of using Tile IDs for frame numbers mainly because they're not dependable.


I haven't had an issue with using tile IDs for animation frames so far. I'm using TMXImporterV2.Frame for tile objects and it works just fine. I also started with a set size for tilemaps using a single image in Tiled, so maybe that's why it's working for me. Either way, I sure would like to be able to get the tile ID for objects so I can optimize collisions a bit more :).
B
80
S
46
G
24
Posts: 525
Reputation: 20,955

Post » Mon Mar 27, 2017 9:53 am

Update

rex_tmximporterV2 plugin:
- now expression:Frame( gid ) could get frame number by gid (ex. TMXImporterV2.ObjectRefGID),
or expression:Frame to get frame number of current tile.


@faulknermano
@digitalsoapbox
Do I miss it?
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Mon Mar 27, 2017 10:25 am

Update

rex_tmx_importerV2 plugin:
- fix bug when iterating object properties.


@mku91
Sorry for late.
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Fri Jun 16, 2017 10:18 pm

@Rexrainbow - The exported json and xml data from tiled seems to come out different then your example files, which version of tiled did you use when you were making this plugin?

thanks
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Sat Jun 17, 2017 1:35 am

@justifun

I could not remember.
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Sat Jun 17, 2017 3:48 am

@rexrainbow - i figured out that i needed to find/replace all " with "" for it to work in C2 properly.

my next question (which i also sent to you in discord) is...

Is it possible to use tile custom properties, when using the TMX import with the tilemap ? I saw how you used properties in your other json examples where you are generating lots of tiles, buti'm trying to avoid that by using the tilemap method.

Can i do something like "if tile property = "rock" -> create rock sprite at tile.x, tile.y?

thx
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Sat Jun 17, 2017 7:04 am

@justifun

Uses "Action:Retrieve tile array" then creating tiles under "Condition:On each tile cell" with (Expression:PhysicalX , Expression:PhysicalY), Expression:TileProp( name )
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Thu Jun 22, 2017 4:53 am

hello again @rexrainbow - 2 questions for you.

1) not sure if this is a bug or not. When using the action "set instance at position" it will correctly offset the tile layer, but the object layer will not get offset. it remains at 0,0. is there something else i need to do to make the object layer line up with the tiles like in the tiled editor

2) is it possible to have multiple tmx map files all referencing the same .tsx tileset to reuse tiles between maps? is there an option in tiled, or a way to import .tsx files into c2 to resue the tilesets between maps?

thanks
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 5 guests