Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
pauljessup
Party member
Posts: 356
Joined: Wed Jul 03, 2013 4:06 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by pauljessup »

Why not just use Insert Tile on the object layer, and have a tileset setup just for object/tiles in TileD? Then when you bring it in through Lua, you can bring in all the custom properties and stuff...

It's what I'm doing in my next project
lemonstale
Prole
Posts: 1
Joined: Fri Jun 04, 2021 3:12 am

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by lemonstale »

Sorry if this is a dumb question but how do I get the data from objects in the tilemap? Such as xy coordinates if I wanted to place an npc on the map and then make it move in the game.
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 »

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: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by ClaudeM »

Hi,

I am using Löve2D & physics with Tiled & STI. I am missing something. The shapes for the rocks are piled in the top left corner, instead of being attached to the sprites. Using the master from 2021-03-27 helped: all the rock shapes were centred on 0,0 when I used 1.2.3.0. I am attaching a screen capture image.

The bulldozer moves with forces; getting that working was very satisfying. There are two big problems looming on the horizon: how to move the map when the bulldozer get close to the edge and adding friction for the rocks.

Sometimes this feels overwhelming. Small successes keep me going.

I appreciate any help you can provide.

Thanks.
Attachments
Bulldozer-20211113.png
Bulldozer-20211113.png (180.97 KiB) Viewed 11875 times
User avatar
ClaudeM
Prole
Posts: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: bulldozer and rocks - collision boxes in the wrong place

Post by ClaudeM »

The white lines are drawn by the sketchy library. Each rock has a corresponding collection of triangles which were created by STI's box2d plugin. The size and shape match the rocks. When I dump the collisions table, I see eight sets of objects; each set has the same x,y coordinates. The coordinates look OK - roughly matching the position of the rocks (did not take the time to measure).

I can drive the bulldozer through the rock sprites, but it is stopped by the collision boxes in the top left corner. When the bulldozer hits the collision box at an angle it rotates. Physics is great!

Trying to read and understand the box2d plugin code, but not making much progress.

Oh! I do not know why the collision boxes are now piling on the right; before, they were piling down. I assume they cannot occupy the same space and are moved by the physics engine, but does not quite work - there is some overlap.

At this point, it looks like a bad interaction between the map and STI. Are there secrets to making a map that works well with STI?
Attachments
blocked_20211116.png
blocked_20211116.png (38.7 KiB) Viewed 11749 times
through_rocks_20211116.png
through_rocks_20211116.png (38.33 KiB) Viewed 11749 times
User avatar
ClaudeM
Prole
Posts: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by ClaudeM »

Trouble with Tiled

I changed the rock tile in the map to have both collidable and dynamic custom properties. Completely different result: there is a factor of 2 position offset, the shapes are wrong, there is one left-over correct shape, and I can push the rectangles.

The contents of the map's Lua file look a bit odd.

Code: Select all

          id = 252,
          type = "rock",
          properties = {
            ["collidable"] = true,
            ["dynamic"] = true                                                            
          },
The fact that the code took the dynamic body path confirms that the custom properties are correct, right?

I will return to this later.
Attachments
bulldozer-collision-boxes-in-the-wrong-place-20211116.png
bulldozer-collision-boxes-in-the-wrong-place-20211116.png (212.77 KiB) Viewed 11737 times
Last edited by ClaudeM on Sun Nov 21, 2021 9:50 pm, edited 1 time in total.
User avatar
ClaudeM
Prole
Posts: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by ClaudeM »

Hi,

The nine rectangles collide and move when pushed by the bulldozer. The triangulated rock shape collides with the bulldozer and does not move.

The first nine collision table entries look like this (they have different positions). The missing 'ox' is surprising; I wonder if it is related to the offset in the X axis.

Code: Select all

 	object
 	 	layer	table: 0x41c68348
 	 	x	192
 	 	batch	SpriteBatch: 0x55d1d7d31050
 	 	id	1
 	 	gid	253
 	 	oy	32
 	 	r	0
 	 	y	58
 	body	Body: 0x55d1d7eb53b0
 	shape	PolygonShape: 0x55d1d782f8c0
 	fixture	Fixture: 0x55d1d7d360e0
There are six other entries in the collision table after those. They look like this and they look wrong: the object has a rectangle shape and the collision has a polygon shape. The polygon shape is right for a rock, but there are nine rocks and six of these entries in the collision table.

Code: Select all

 	object
 	 	layer	table: 0x41c68348
 	 	x	150.667
 	 	shape	rectangle
 	 	id	29
 	 	y	99.3267
 	 	properties	table: 0x4040ba00
 	 	visible	true
 	 	gid	253
 	 	rotation	0
 	 	type	
 	 	name	
 	 	height	32
 	 	width	32
 	body	Body: 0x55d1d782f890
 	shape	PolygonShape: 0x55d1d7ecdbb0
 	fixture	Fixture: 0x55d1d7ecdac0
Is my problem a failure to understand the Tiled editor? If so, where can I find documentation for the relationship between Tiled and Box2D?

Thank you.
Last edited by ClaudeM on Sun Nov 21, 2021 9:50 pm, edited 1 time in total.
User avatar
ClaudeM
Prole
Posts: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by ClaudeM »

I have added debugging code to plugins/box2d.lua around line 53. The cascading if-else did not have an else branch and assigned the default on variable declaration. When I run the game, it takes the default path for most things and creates six new dynamic bodies which I cannot find when I drive the bulldozer around.

Does this means that I am not using Tiled correctly? I added user properties to the rock in the tile set, not on each individual rock after I placed it on the map. Is that the problem? Thanks.

Code: Select all

            local currentBody
            --dynamic are objects/players etc.
            if userdata.properties.dynamic == true then
                print("new dynamic body")
                currentBody = love.physics.newBody(world, objx, onjy, 'dynamic')
            -- static means it shouldn't move. Things like walls/ground.
            elseif userdata.properties.static == true then
                print("new static body")
                currentBody = love.physics.newBody(world, objx, onjy, 'static')
            -- kinematic means that the object is static in the game world but effects other bodies
            elseif userdata.properties.kinematic == true then
                print("new kinematic body")
                currentBody = love.physics.newBody(world, objx, onjy, 'kinematic')
            else
                print("use existing body")
                currentBody = body
            end
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 »

It's been a while since I have looked at that code but there could very well be a bug somewhere. You should be able to place properties on the tile set but that may have gotten broken at some point. If you find any bugs, feel free to send a pull request~
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: 31
Joined: Sat Oct 16, 2021 6:27 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by ClaudeM »

Aha! Adding "static" user properties to the collidable tiles and setting them to true changes things a lot. There are now extra collision rectangles; there is an odd pattern.
game_with_extra_static_collision_boxes_20211121.png
game_with_extra_static_collision_boxes_20211121.png (119.49 KiB) Viewed 11075 times
Tiled editor seems to know about the actual polyline and polygon collision boxes.
Tiled_shows_correct_collision_boxes_20211121.png
Tiled_shows_correct_collision_boxes_20211121.png (111.05 KiB) Viewed 11075 times
Have I gone off the beaten path? Has anyone ever used Tiled, STI, and Box2D?

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests