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 »

Hi markusm,

I am also new to LÖVE2D. I started with a very simple « click on the target » game from a video on YouTube. I then build Bulldozer in steps: I got a copy of Tiled (the editor), found a tile set I liked, made a map, and loaded it in a rudimentary game (it did almost nothing). I added things to it one at a time: sound, an object layer, and the bulldozer. I added LÖVE2D physics later; it took a long time to get the bulldozer moving well.

I then worked on collisions with physics. LÖVE2D uses the Box2D library; it is excellent and well known. This is a complex element of the game. I made the choice to use physics because later stages of the game will benefit from it (e.g., you cannot push too many rocks at a time). You may not need physics; one alternative is bump https://love2d.org/wiki/bump.lua.

When I started having difficulty with collisions, I made a smaller 8 x 8 map with only one rock. I added a lot of print statements to see what was happening. Print is your friend. If there is a lot of output, pipe it into a file you can examine more conveniently with something like the 'less' command.

The world.lua file you provided is quite different from the one I am using. I have not seen chunks before, but may not mean much since I am a beginner with Tiled editor. Here is a half-size screenshot of Tiled with my small testing map. I put the ground tiles in one layer and the rock on an object layer. You can see the dashed lines of the collision boxes; I added those to the tile-set.

There are other tricks with using Tiled. It took me a while to learn.

Good luck in your development.
Tiled_editor_half-size_20211205.png
Tiled_editor_half-size_20211205.png (322.49 KiB) Viewed 13651 times
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 »

P. S. I tried using your map with the example in the STI GitHub page and also got a blank window. I suggest starting with that code.

https://github.com/karai17/Simple-Tiled-Implementation
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 »

I don't believe infinite maps / chunked maps currently work with STI. You will need to change your map properties to have a fixed size.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
markusm
Prole
Posts: 3
Joined: Sun Dec 05, 2021 7:23 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by markusm »

Thanks everybody for the feedback! I will try fixed sized maps.

And thanks Claude for giving me the Bulldozer example, looks like a fun game. Can I do something to debug the crash I have on my MacBook Pro ? Do not really know how to provide debug information with Love2D right now.

Thanks,
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 »

Is it a hard crash or are you getting the blue screen with white text? If the latter, you can post a screenshot of that as it should tell you where the error is occuring and give a stack trace for how that function got called. If the former, might want to pop into the LOVE Discord and @slime with more details.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
markusm
Prole
Posts: 3
Joined: Sun Dec 05, 2021 7:23 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by markusm »

It's not a crash per se but the app hangs and the audio channel goes wild, have to kill the process in the task manager.

Ok, will join the discord and message @slime. Thanks.
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 »

Found the problem with rock object positions being off by a factor of two: vertices are relative to the object, do not add the position of the object. Here is the section of sti/plugin/box2d.lua

Code: Select all

            elseif o.shape == "polygon" then
                -- Recalculate collision polygons inside tiles
                if tile then
                    local cos = math.cos(math.rad(o.r))
                    local sin = math.sin(math.rad(o.r))
                    for _, vertex in ipairs(o.polygon) do
--                      vertex.x = vertex.x + o.x
--                      vertex.y = vertex.y + o.y
                        vertex.x, vertex.y = utils.rotate_vertex(map, vertex, o.x, o.y, cos, sin)
                    end
                end

                local vertices  = getPolygonVertices(o)
                local triangles = love.math.triangulate(vertices)

                for _, triangle in ipairs(triangles) do
                    addObjectToWorld(o.shape, triangle, userdata, tile or object)
                end 
Bulldozer_20211207.png
Bulldozer_20211207.png (41.22 KiB) Viewed 13564 times
Time to write the code to move the rock sprite to match the physics engine's position for the rock.
Attachments
bulldozer-0.15.zip
(2.68 MiB) Downloaded 352 times
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 »

Hi,

After looking more at the Box2D plugin code, I see that static elements of a tile can be associated with the main body (the first one created in box2d_init). For those, adding the tile position is required. The code must recognize this situation; there must be cooperation between the Box2D plugin and the way the map is designed in Tiled editor.

Is there an established convention? Would this work? Mark a tile layer as collidable and static while leaving the individual tiles un-marked; the code can detect this and do the right thing. The other case is an object layer with some collidable objects marked dynamic and some marked as static. Oh, the comments at the bottom of the Box2D plugin do not mention a static property. Should static objects be marked "dynamic: false" ? We can also say that the absence of the dynamic property means static.

Thoughts?

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

Hi Karai17,

Where in the map does the draw function get the x, y, and r ? I want to update dynamic object tiles (images) and tried updating the tileInstances table, but it has no effect. I looked at the main STI function (init.lua) and had a hard time following the code.

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

tiles get batched so you need to remove it from the batch, update the instance, then add it back to the batch
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests