Page 90 of 92

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Dec 27, 2021 5:19 pm
by ClaudeM
Manipulating sprite batches is complicated and inefficient (when done sixty times per second). I made a table of dynamic objects containing body and tile pairs. There will not be many dynamic objects; this should be fast enough. I works well.

Next step: fix the mass & inertia, maybe add friction.

Code: Select all

    box2d_update = function(map)
        -- use a special purpose table
        --
        -- the body has the updated position
        -- and the tile has the texture image and the offset
        --
        local x, y, r, ox, oy
        for _, dTile in ipairs(map.box2d_dynamicTiles) do
            x, y = dTile.body:getPosition()
            r = dTile.body:getAngle()
            ox = dTile.tile.objectGroup.objects[1].x
            oy = dTile.tile.objectGroup.objects[1].y
            lg.draw( map.tilesets[dTile.tile.tileset].image, dTile.tile.quad,
                     x, y, r, dTile.tile.sx, dTile.tile.sy, ox, oy)                       
        end
    end,

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Dec 27, 2021 5:22 pm
by Karai17
Updating sprite batches every frame is MUCH faster than drawing individual sprites every frame.

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Tue Dec 28, 2021 10:26 pm
by ClaudeM
So I would use the following function. The sprite batch seems to be an opaque structure. How can I discover the sprite index for each dynamic object? I will investigate. Thanks.

Code: Select all

SpriteBatch:set( spriteindex, x, y, r, sx, sy, ox, oy, kx, ky )

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Tue Dec 28, 2021 10:57 pm
by Karai17
the tile instance should have a reference to the batch and the index thereof.

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Apr 04, 2022 8:18 pm
by pauljessup
Looks like the latest version of Tiled (1.8( Throws an error (note, I am not using a collection. The Tileset is a single png image, referenced in a tmx tileset...latest version of STI downloaded from github)

Error:

Error

engine/sti/init.lua:99: STI does not support Tile Collections.
You need to create a Texture Atlas.


Traceback

[C]: in function 'assert'
engine/sti/init.lua:99: in function 'init'
engine/sti/init.lua:48: in function 'sti'
engine/map.lua:10: in function 'load'
main.lua:26: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Apr 04, 2022 8:20 pm
by pauljessup
Just tested a game I used STI and Tiled with and saved the map with 1.8, and yup same thing happened. Just an FYI

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Apr 04, 2022 9:38 pm
by Karai17
Noted. I plan on overhauling STI at some point in the nearish future but if anyone wants to contribute a fix in the meantime, I take PRs hot or cold. ;)

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Apr 04, 2022 10:33 pm
by pauljessup
I'll take a look and see if I can figure it out...finger's crossed

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Mon Apr 04, 2022 10:45 pm
by pauljessup
Aha, I see what happened, when you export to Lua it doesn't embed a table with the image and tileset details, instead it just links to the tsx file. I'm not sure if this was intentional, I'll bring it up to the creator of TileD and see if this is how it's supposed to work, or if it should be embedding that lua info like it used to.

Re: Simple Tiled Implementation - STI v1.2.3.0

Posted: Tue Apr 05, 2022 1:57 pm
by pauljessup
Okay, I got a response- what you need to do now in version 1.8 is go to preferences, click on "Embed Tilesets on Export". It doesn't allow you to embed a tileset directly in the map anymore in the editor, it's only done on export.