Page 43 of 92
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Wed Dec 30, 2015 10:55 am
by Karai17
Ah, you mean for draw range. That is something I can work on, yes. You can just disable draw range for now though and it will draw the whole map. This would normally be a bad thing, but since STI uses sprite batches, you aren't making *that* many draw calls. It might be a bit of a snag on mobile, but on a desktop it should run totally fine with drawrange turned off until it is fixed.
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Thu Dec 31, 2015 1:12 am
by TooMuchAbstraction
Hello, and thanks for adding this functionality to love2d! I'm starting work on a basic platformer based off of
this old example. I've made a ton of changes, and one of the things I want to do is switch to STI instead of using Advanced Tiled Loader.
The actual switch went smoothly, but now I need to re-implement one of the modifications that I did with the map as loader by ATL, which is to cull unnecessary edges from the terrain collision detection. Say for example that I have a row of square tiles. If I make a square hitbox for each tile in the row, then I have a bunch of extra edges that the player never ought to be able to run into, but actually can due to the vagaries of how box2d does collision detection. My fix under ATL was to manually generate all of my collision edges using love.physics.newEdgeShape, and adding only those edges that were not adjacent to another solid tile.
It looks, from examination of sti/plugins/box2d.lua, like STI supports specifying custom polygons/polylines for tile collision, which I can probably use as an alternative to manually constructing the hit detection at runtime. In fact it's preferable since I should be able to then create my own sloped tiles and have them Just Work. However, I can't figure out how to access this functionality. I tried setting some custom properties of the tile in Tiled, but they don't appear to have any effect, and I can't find any documentation indicating what I should do. I'm looking specifically at the calculateObjectPosition() method. It seems like it should be able to specify a "shape" property and a "polygon" property, something like this:
(this is looking at the properties of a tile in a tileset)
But this doesn't work. Is there some way to achieve this?
Thanks for your time!
EDIT: some digging shows that it's possible to modify STI to get the polygon "shape" by using "tile.properties.shape or "rectangle"" instead of just "rectangle" whenever it calls calculateObjectPosition. And the custom polygon vertices can be accessed in calculateObjectPosition by adding "or object.properties.polygon" to the "polygon" property of the initialization of the "o" object. However, that property is a string, instead of table of vertex pairs, and I don't know how to convert a string into a list of vertex pairs.
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Thu Dec 31, 2015 7:31 am
by Karai17
Just add the "collidable" property to your object or object layer and set the value to true.
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Thu Dec 31, 2015 3:21 pm
by TooMuchAbstraction
Karai17 wrote:Just add the "collidable" property to your object or object layer and set the value to true.
Yes, I did that, but it just generates a rectangle for every tile. This creates a bunch of unnecessary collision edges between adjacent tiles (which causes collision glitches), and it also means that I can't have sloped tiles.
In any event, check your pull requests.
Here is an example map that encodes custom collision polygons for some of the tiles, and
here are the two tilesets I'm using. The one that doesn't look horribly unprofessional comes from
this old tutorial.
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Thu Dec 31, 2015 4:26 pm
by Karai17
You can also just create an object layer and manually stick in a few rectangles to cover areas greater than a single tile, or polygons for sloped edges. I looked at your pull request and I personally just don't see the problem that it solves that can't be solved by just using Tiled properly.
Re: Simple Tiled Implementation - STI v0.14.1.8
Posted: Thu Dec 31, 2015 8:05 pm
by TooMuchAbstraction
For reference, Karai and I sorted this out. Turns out that STI wasn't loading the object group for each tile, which means that any custom collision data added via the Tile Collision Editor wasn't getting loaded and the tiles were defaulting to a rectangular collision hitbox. This is now fixed.
Re: Simple Tiled Implementation - STI v0.14.1.10
Posted: Thu Dec 31, 2015 9:00 pm
by Karai17
I would also like to note that this used to work! It must have broke when I implemented the plugin system ?????
Re: Simple Tiled Implementation - STI v0.14.1.10
Posted: Fri Jan 01, 2016 12:48 am
by TooMuchAbstraction
Since I'm here already, I'd like to be able to place items on the map, which can be picked up by the user. At the moment I have an object layer, and at program start, I'm iterating over all objects in the map and creating bodies and fixtures for them so I can recognize when the player touches them. This works okay, but I can't figure out how to then remove the items from the map. I can remove the bodies I created easily enough, but I can't get the map to stop drawing them.
Is there some other way I should be approaching this? Should I be creating a sprite layer or something?
Re: Simple Tiled Implementation - STI v0.14.1.10
Posted: Fri Jan 01, 2016 12:49 am
by bobbyjones
The tutorial on lua.space shows how to remove objects I think.
Re: Simple Tiled Implementation - STI v0.14.1.10
Posted: Fri Jan 01, 2016 1:21 am
by Karai17
You can remove the objects from map.objects and from the layer to kill them. If you are using a tile object you may need to regenerate the batches