Simple Tiled Implementation - STI v0.18.2.1

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Posts: 63
Joined: Mon Dec 04, 2017 1:47 am

Re: Simple Tiled Implementation - STI

Post by modiX » Wed Feb 14, 2018 11:52 pm

Karai17 wrote:
Tue Feb 13, 2018 11:13 am
I had asked vrld if he wanted to make an HC plugin for STI but he was busy at the time and I also got busy too. I made the box2d plugin as a reference and the bump plugin was made by a third party. If you want to make an HC plugin, I'd be very happy to accept a pull request. :)
Great to hear, I already started, but I'm not sure how fast it will be done. As of now it supports only rectangles and polygons on simple tiles (no objects), since I only need that as of now.

I will consider to pull request, when I get something more complete on it.

Visual Studio Code Template

User avatar
Party member
Posts: 836
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 » Thu Feb 15, 2018 12:38 pm

Cool, I look forward to it. :)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

Posts: 3
Joined: Tue Feb 13, 2018 7:15 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Saoskia » Sun Feb 18, 2018 1:00 pm

Saoskia wrote:
Tue Feb 13, 2018 2:23 pm
Thanks for the quick reply :awesome:

I checked out the OP, and I managed to get a collider onto the player object, but it's not working properly.
The player itself (the image) can still cross over other colliders. The player's collider does its best to actually collide with the other colliders, but ultimately will follow the player. I've managed to record a gif to show what I mean.


How can I make sure the sprite image stops moving when the collider does?

Code: Select all

-- Include Simple Tiled Integration into project
local sti = require "sti"

function love.load()
    -- Load map file
    map = sti("maps/hi.lua", { "box2d" })

    -- Create world
    world = love.physics.newWorld(0, 0)

    -- Create new dynamic data layer called "Sprites"
    local layer = map:addCustomLayer("Sprites", 4)

    -- Get player spawn object
    local player
    for k, object in pairs(map.objects) do
        if == "Player" then
            player = object

    -- Create player object
    local sprite ="images/purple.png")
    layer.player = {
        sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 2

    -- Add physics to player object
    layer.player.body = love.physics.newBody(world, layer.player.x, layer.player.y, "dynamic")
    layer.player.shape = love.physics.newRectangleShape(sprite:getWidth(), sprite:getHeight())
    layer.player.fixture = love.physics.newFixture(layer.player.body, layer.player.shape)

    -- Add controls to player
    layer.update = function(self, dt)

        local speed = 200

        -- Move player up
        if love.keyboard.isDown("w") then
            self.player.y = self.player.y - speed * dt

        -- Move player down
        if love.keyboard.isDown("s") then
            self.player.y = self.player.y + speed * dt

        -- Move player left
        if love.keyboard.isDown("a") then
            self.player.x = self.player.x - speed * dt

        -- Move player right
        if love.keyboard.isDown("d") then
            self.player.x = self.player.x + speed * dt


    -- Draw player
    layer.draw = function(self)
            0, 1, 1,
        )"line", self.player.body:getWorldPoints(self.player.shape:getPoints()))        

        -- Temporarily draw a point at our location so we know
        -- that our sprite is offset properly, math.floor(self.player.y))

    -- Remove unneeded object layer
    map:removeLayer("Player Spawn")


function love.update (dt)
    -- Update world

function love.draw()
    -- Draw world
    map:box2d_draw(world, 0, 0, 0, 0)
Update on my previous post.

Not sure if this is worth mentioning, but when I was going over the code from the OP, I noticed that in love.update, world:update(dt) was being called before map:update(dt), which is different to mine. After changing the order of these two lines, the collisions in my program stopped working altogether.

Hopefully that might help someone :)

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests