Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ClaudeM
Prole
Posts: 30
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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,
Attachments
bulldozer.zip
(2.75 MiB) Downloaded 303 times
Bulldozer_20211227.png
Bulldozer_20211227.png (43.92 KiB) Viewed 12185 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by Karai17 »

Updating sprite batches every frame is MUCH faster than drawing individual sprites every frame.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
ClaudeM
Prole
Posts: 30
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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 )
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by Karai17 »

the tile instance should have a reference to the batch and the index thereof.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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'
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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. ;)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by pauljessup »

I'll take a look and see if I can figure it out...finger's crossed
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post 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.
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

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

Who is online

Users browsing this forum: Majestic-12 [Bot] and 17 guests