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