Page 13 of 92
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Fri Mar 21, 2014 3:06 am
by ochetski
Karai17 wrote:You should be able to access map.tilewidth and map.tileheight without any problem.
Oh, I don't noticed that, Karai. I was looking for the size somewhere with collision map type, orientation, collision and so.
Cerulean Knight wrote:ochetski wrote:I asked because I did implemented a collision system with STI. But needed to set the tile sizes hard coded, because I wasn't able to get tiles width and height from the map.
My collision system is now ugly, complex and hard to use with multiple entities. I will probably change it to use love.physics. I will share it here as soon as I finish it.
Thanks Karai, please keep the good work because it will bring great games to life.
If you are using HardonCollider, you can add a few lines in the Map:getCollisionMap function.
So, the final result is this (if you are using 32x32 tiles):
Code: Select all
function Map:getCollisionMap(index)
local layer = assert(self.layers[index], "Layer not found: " .. index)
assert(layer.type == "tilelayer", "Invalid layer type: " .. layer.type .. ". Layer must be of type: tilelayer")
local w = self.width
local h = self.height
local map = {
type = layer.type,
orientation = layer.orientation,
collision = true,
opacity = 0.5,
data = {},
}
for y=1, h do
map.data[y] = {}
for x=1, w do
if layer.data[y][x] == nil then
map.data[y][x] = 0
else
map.data[y][x] = 1
ctile = collider:addRectangle((x-1)*32, (y-1)*32, 32, 32)
collider:setPassive(ctile)
end
end
end
return map
end
Then, when you load a collision map, HC will create all invisible square on the map positions.
Note: collider is the variable that you define before
Code: Select all
collider = HC(100, on_collision,stop_collision)
That's what I will do, but I'm really thinking about use love.physics. And keep it apart from STI to keep things easy to update.
Thanks!
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Fri Mar 21, 2014 3:22 am
by Cerulean Knight
It will be great when in tiled we can edit the collisions in each tile. In the 9/03 daily version it's avalaible, but it is not exported into lua.
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Fri Mar 21, 2014 3:46 am
by Karai17
Built in collision? Can you explain more?
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Fri Mar 21, 2014 11:23 am
by Cerulean Knight
It's on the
9/03 daily version of tiled.
And here is the new part of the tmx file:
Code: Select all
<tile id="32">
<objectgroup draworder="index">
<object x="32.625" y="31.125">
<polyline points="0,0 -0.25,0.5"/>
</object>
<object x="13" y="0" width="18.75" height="31.875"/>
</objectgroup>
</tile>
<tile id="43">
<objectgroup draworder="index">
<object x="0.125" y="0" width="22" height="31.875"/>
<object x="22.125" y="13.375" width="9.75" height="18.5"/>
</objectgroup>
</tile>
</tileset>
The 32 had a polygon point by point (looks like I'll never use it), and the 43 had 2 rectangles, but It is not exported to lua yet.
This editor and animation will be great in the next version (:
Edit: Oh, I noted that animations are exported.
Code: Select all
<tile id="43">
<objectgroup draworder="index">
<object x="0.125" y="0" width="22" height="31.875"/>
<object x="22.125" y="13.375" width="9.75" height="18.5"/>
</objectgroup>
<animation>
<frame tileid="9" duration="100"/>
<frame tileid="33" duration="100"/>
<frame tileid="37" duration="100"/>
</animation>
</tile>
</tileset>
Code: Select all
tiles = {
{
id = 43,
animation = {
{
tileid = "9",
duration = "100"
},
{
tileid = "33",
duration = "100"
},
{
tileid = "37",
duration = "100"
}
}
}
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Wed Mar 26, 2014 9:42 pm
by blkducky
So does this just not support tiles in object layers yet?
Left is LÖVE window, right is Tiled. The rectangle object is on the same layer as the stuff on the table but obviously only the rectangle appears.
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Wed Mar 26, 2014 11:42 pm
by Karai17
Can you post a .love so I can examine the map file(s)?
Re: Simple Tiled Implementation - STI v0.6.16
Posted: Thu Mar 27, 2014 7:43 pm
by blkducky
Minimum code needed to replicate it. It just never draws tile objects for me.
(LÖVE 0.9.0, Tiled v0.9.1 - daily build from a few days ago)
Re: Simple Tiled Implementation - STI v0.7.2
Posted: Mon Apr 07, 2014 4:29 am
by Karai17
Sorry for the very late reply. I'm going to be poking at STI tonight so hopefully I can get this sorted out.
Edit: STI now has support for non-LOVE frameworks, though none are built yet. If anyone wants to extend it, please push your changes upstream!
Edit 2: STI now draws to canvas before drawing to screen, this should fix some graphical glitches when scaling a map.
Edit 3: Removed dependency for LuaJIT's bitwise operations.
Re: Simple Tiled Implementation - STI v0.7.4
Posted: Tue Apr 29, 2014 1:10 am
by Karai17
Fixed a couple bugs~
Re: Simple Tiled Implementation - STI v0.7.4
Posted: Tue Apr 29, 2014 1:29 am
by danbo
Used this for
Ludum Dare, much nicer to get off the ground with than ATL.
The double-step of having to export as lua table is a little irritating, but it's a price I happily paid.