Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
TooMuchAbstraction
Prole
Posts: 7
Joined: Thu Dec 31, 2015 12:58 am

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by TooMuchAbstraction »

Yep, figured it out, thanks! Here's what I'm doing (powObject is the map object, powFixture is the associated fixture I created):

Code: Select all

        -- Delete the object from the map's object list.
        map.objects[powObject.id] = nil
        -- Delete the object from the layer in the map it is in.
        local newObjects = {}
        for i, obj in ipairs(powObject.layer.objects) do
            if obj ~= powObject then
                table.insert(newObjects, obj)
            end
        end
        powObject.layer.objects = newObjects
        -- Stop drawing the object.
        map:setObjectSpriteBatches(powObject.layer)
Next question: I want to have multiple maps that smoothly connect to each other -- each map is a separate "room", and I want to be able to assemble different arrangements of rooms on the fly, so I don't even know what their positions will be relative to each other until runtime. This requires me to offset the map and its collision data. I added this method to the Map class, which causes it to draw the map at a different location:

Code: Select all

function Map:offset(dx, dy)
    self.offsetx = self.offsetx + dx
    self.offsety = self.offsety + dy
    for _, layer in pairs(self.layers) do
        layer.x = layer.x + dx
        layer.y = layer.y + dy
    end 
end
and offset the collision detection with this:

Code: Select all

local body = map.box2d_collision.body
body.setPosition(body.getX() + dx, body.getY() + dy)
But bizarrely, I have to apply 2x the translation to the body that I do to the map. Like, if I move the collision body by (50, 50) then I have to call map:offset(25, 25). Any idea why that is?

More importantly, the map refuses to draw if it moves too far. I'm guessing there's some kind of automatic culling going on. What's the recommended way to deal with this? Am I barking up the wrong tree entirely?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by Karai17 »

I already added this functionality a few weeks or so ago. Just pass in an offset_x and offset_y (in pixels) after the plugins table in STI.new and it Just Works.

Code: Select all

local sti = require "sti"
local map = sti.new("some_map.lua", {}, 500, 500)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
TooMuchAbstraction
Prole
Posts: 7
Joined: Thu Dec 31, 2015 12:58 am

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by TooMuchAbstraction »

Awesome! But, some bad news: that doesn't affect the collision detection. This is easily fixed though! Just modify box2d_init so that its initialization of the "body" local looks like

Code: Select all

local body      = love.physics.newBody(world, map.offsetx, map.offsety)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by Karai17 »

Hm, that's a point. I'll add that to box2d and bump within the next couple days or so, or feel free to send a PR.

Actually, can you test to see if it works with Bump? I am fairly certain I had collision working but I could be wrong.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
TooMuchAbstraction
Prole
Posts: 7
Joined: Thu Dec 31, 2015 12:58 am

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by TooMuchAbstraction »

I have zero familiarity with bump, and my code is already somewhat heavily-tied to box2d so it's not trivial to test bump. However, a quick look at bump.lua shows no reference to map.offsetx or map.offsety, so I doubt that it works properly.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Simple Tiled Implementation - STI v0.14.1.10

Post by bobbyjones »

I'll test.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.14.1.11

Post by Karai17 »

I've merged in a few pull requests that fix both plugins. hi5!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
MikaelS
Prole
Posts: 2
Joined: Fri Oct 16, 2015 8:30 pm

Re: Simple Tiled Implementation - STI v0.14.1.11

Post by MikaelS »

I asked you earlier about conversion of hexagonal coordinates to orthogonal and vice versa. Have you had any time to look into this? I tried myself using the code in Map:setSpriteBatches() because as far as I can tell this is where the same conversion takes place for the tiles themselves, but I haven't been successful so far.
premek
Prole
Posts: 21
Joined: Mon Dec 28, 2015 12:44 am
Contact:

Re: Simple Tiled Implementation - STI v0.14.1.8

Post by premek »

premek wrote:

Code: Select all

        for k,v in ipairs(map.layers.objects.objects) do
          if v.id == item.id then
            table.remove(map.layers.objects.objects, k)
          end
        end
        table.remove(map.objects, item.id)
        map:setObjectSpriteBatches(map.layers.objects)
Hi, I have one more question regarding manipulating map objects.
When I want to move an object on a map, I use this code:

Code: Select all

  moveObjectByItem = function(map, item)
    for k, obj in ipairs(map.layers.objects.objects) do
      if obj.id == item.id then
        map.layers.objects.objects[k].x = item.x
        map.layers.objects.objects[k].y = item.y+item.height
      end
    end
    map.objects[item.id].x = item.x
    map.objects[item.id].y = item.y+item.height
    map:setObjectSpriteBatches(map.layers.objects) -- FIXME this resets all objects animation when any object moves
The problem is that objects animations on the same layer are reset every time I call setObjectSpriteBatches (which is every frame when some object is moving) and then it looks like animations stops when an object is moving.

Is there any way to do it better?
Thanks!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.14.1.11

Post by Karai17 »

I would not actively use object layers, I would transfer object data over to a custom layer if you plan to create dynamic objects.
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: Bing [Bot], Majestic-12 [Bot] and 7 guests