[plugin] rex_tmx_importer_v2

0 favourites
From the Asset Store
Antisuspend Plugin for Construct 3 prevents the runtime from getting suspended.
  • 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

    > 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.

  • 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.

  • 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 .

  • 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?

  • Update

    rex_tmx_importerV2 plugin:

    • fix bug when iterating object properties.

    mku91

    Sorry for late.

  • 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

  • justifun

    I could not remember.

  • 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

  • justifun

    Uses "Action:Retrieve tile array" then creating tiles under "Condition:On each tile cell" with (Expression:PhysicalX , Expression:PhysicalY), Expression:TileProp( name )

  • 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

  • Update

    Now "Expression:ObjectX", "Expression:ObjectY" will shift with "Expression:POX", "Expression:POY".

    justifun

    1) added in latest version. But I don't have time to test it carefully.

    2) I have no idea about importing tsx files to C2. I guess that it is impossible.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • rexrainbow - Thanks! I'll check it out and report back any bugs!

    For those of you who might have been trying to figure out multiple maps vs one tileset the workflow i found that works ok is.

    Make a tileset and leave it open in tiled. Then create a new Map for each level you want to design. Drag your pieces from the one tile set into your map and design it.

    Save a copy of your map seperately then you main one as a backup.

    Click the button in the tileset window that says "Embed Tileset into map"

    Save your map file into your C2 Project folder

    By embedding your tileset into the map file the data will be accessible from the TMX importer. However you need to make sure you make a backup of the TMX map because you want to keep your master map files NOT have the tileset embedded into it, so that you can use the same tileset for all maps.

    Not sure how to un-embed a tileset from a map

  • Update: ok after more testing this issue is still present. If you are using objects with custom properties as opposed to tiles, the imported wont pick them up.

    rexrainbow - Hello again!

    I still have to verify the new object offset feature you added, but in the mean time i came across another issue with the TMX importer.

    When using the Tiled map editor object layer, and you add objects via the "Insert Tile" button (the one that has a little image icon). Any custom properties on these objects will show up in the property window, however they wont be read by the importer

    Here's an example.

    If I save the file after adding a few tiles, None of the custom properties show up in the tmx data in the <objectgroup> <properties> section where i believe your plugin is looking for them.

    However! If you add another random custom property to the object in the map then save it again there is now a new entry in the <objectgroup> at the bottom (its no longer blank), AND the TMX importer now actually reads all the previous custom properties that it was skipping over before.

    It appears that If your importer doesn't find a <properties> section within <objectgroup> they it wont load any of the custom properties that are being added to the file via embedding a external tileset even though the data for that is just in a different location in the .tmx file.

    Example: File saved with only custom object properties being defined in the tileset

     <objectgroup name="Object Layer 1">
      <object id="1" gid="1" x="0" y="1400" width="2064" height="401">
      </object>
     </objectgroup>[/code:3f1gcdbw]
    

    Example: File saved with an extra custom property added before saving

     <objectgroup name="Object Layer 1">
      <object id="1" gid="1" x="0" y="1400" width="2064" height="401">
       <properties>
        <property name="TestProperty" value="TestData"/>
       </properties>
      </object>
     </objectgroup>[/code:3f1gcdbw]
    
    in both examples, up higher in the TMX file the object custom properties are defined but the importer is skipping this data if the <objectgroup> is missing the <properties> section
    [code:3f1gcdbw]  <tile id="0">
       <properties>
        <property name="Damage" type="int" value="1"/>
        <property name="Name" value="LavaPool"/>
        <property name="Solid" type="int" value="1"/>
        <property name="Value" type="int" value="0"/>
       </properties>
       <image width="2064" height="401" source="../Art/Lava_ground.png"/>[/code:3f1gcdbw]
    
    it appears as if its a case of how the map editor is saving the file, but perhaps there's a way to make it work with your importer?
    
    I can be found on discord in your channel if you have further questions: @justifun
    
    thanks!
  • rexrainbow - it seems like this is part of this issue (as is "as intended" by the map editor developer)

    https://github.com/bjorn/tiled/issues/1609

    It doesnt save that information if the object properties havent changed (on the main map).

    So is there a way with your importer to grab the information from the first portion of the TMX file for each tile ID / property instead of looking for it down in the <objectgroup> section at the bottom?

    thanks

  • justifun

    Added to TODO.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)