karai17 / Simple-Tiled-Implementation

Tiled library for LÖVE
Other
840 stars 121 forks source link

STI with bump doesn't work with polygon collision blocks mapped in the collision editor (Tiled) #257

Closed mutantant closed 3 years ago

mutantant commented 3 years ago

Great library, thank you for all your hard work.

An issue I'm running into is when bump is used (not Box2D, which doesn't have this problem), I get an error from bump.lua about "w" being 0 whenever trying to initialize the world with polygonal collision markers set in the collision editor of Tiled.

If the entire tile is set to collidable = true in Tiled, it works fine. If I remove that for the tile itself, and through the collision editor create a polygonal collision shape, and mark that with collidable = true, then I get the following error:

` Error: libs/bump.lua:56: w must be a positive integer, but was 0(number) stack traceback:

    [C]: in function 'error'
    libs/bump.lua:56: in function 'assertIsPositiveNumber'
    libs/bump.lua:63: in function 'assertIsRect'
    libs/bump.lua:621: in function 'add'
    libs/sti/plugins/bump.lua:43: in function 'bump_init'
    main.lua:31: in function 'load'
    [string "boot.lua"]:586: in function <[string "boot.lua"]:585>
    [C]: in function 'xpcall'
    [string "boot.lua"]:793: in function <[string "boot.lua"]:780>
    [C]: in function 'xpcall'

`

And if I create an ellipse instead, drawing the collision layer show little squares were created instead of circles.

Now, if I do the same in Box2D instead of bump, the polygons are correctly loaded and shows in the collision layer, but they are subdivided with a bunch of internal polygonal triangles, which may be normal.

Is this a bump issue? Or something going sideways when STI is sending bump the info in order to initialize the collision world table? Is STI not passing the complex polygonal collision shape to bump? The repo for bump seems to hint it can handle polygonal collision shapes, but perhaps it can't. (Mostly want something to handle slopes and partial tile blocks)

Attached is a zip. Simple, skeletal main.lua with the "map" which is simply a test map filled with random tiles as well as the tmx file and temporary tilesets included, so hopefully it helps understand my problem.

To replicate: open test.tmx. Edit the second tile of the first tileset to have a non-standard collision shape, run in love2d, and it will show the (terrible) test I have running as I learn the features (or crash with the above error).

In fact, I just checked, it's already ready to go with a polygon shaped collision box all set to go. Simply running in Love2D should replicate the error.

karai17 commented 3 years ago

Bump only works with axis-aligned boxes, complex or rotated shapes will not work in Bump~

mutantant commented 3 years ago

Bump only works with axis-aligned boxes, complex or rotated shapes will not work in Bump~

Ahh, I see. I'd read that on the bump repo, but it was followed closely by mention of polygons, so I'd thought simple polys would work.

Thanks!