Simple Tiled Implementation - STI v0.18.2.1

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

Re: Simple Tiled Implementation - STI

Post by Marty » 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 TemplateRichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter)Add me on Discord

───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█

User avatar
Karai17
Party member
Posts: 853
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é

Saoskia
Prole
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.

ColliderFail.gif

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)
    map:box2d_init(world)

    -- 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 object.name == "Player" then
            player = object
            break
        end
    end

    -- Create player object
    local sprite = love.graphics.newImage("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.body:setFixedRotation(true)
    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
        end

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

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

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

        self.player.body:setX(self.player.x)
        self.player.body:setY(self.player.y)
    end

    -- Draw player
    layer.draw = function(self)
        love.graphics.draw(
            self.player.sprite,
            math.floor(self.player.x),
            math.floor(self.player.y),
            0, 1, 1,
            self.player.ox,
            self.player.oy
        )

        love.graphics.polygon("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
        love.graphics.setPointSize(5)
        love.graphics.points(math.floor(self.player.x), math.floor(self.player.y))
    end

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

end


function love.update (dt)
    -- Update world
    map:update(dt)
    world:update(dt)
end


function love.draw()
    -- Draw world
    map:draw()
    map:box2d_draw(world, 0, 0, 0, 0)
end
TiledTest.love
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 :)

User avatar
Stargazer
Prole
Posts: 5
Joined: Thu Apr 19, 2018 1:03 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Stargazer » Thu Apr 19, 2018 1:09 pm

I tried using STI earlier today and my program breaks at the following line:
local sti = require "sti" (Error: sti/init.lua:32: Invalid file type: orld. File must be of type: lua.)

What am I doing wrong?

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

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 » Thu Apr 19, 2018 9:59 pm

You need to add ".lua" to the end of your file name.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

User avatar
Stargazer
Prole
Posts: 5
Joined: Thu Apr 19, 2018 1:03 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Stargazer » Fri Apr 20, 2018 6:18 pm

Thanks!

KyleFlores1014
Citizen
Posts: 72
Joined: Thu May 25, 2017 1:43 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by KyleFlores1014 » Sat Apr 28, 2018 1:38 pm

Im trying to make my own filter in Bump

Code: Select all

filter =  function(item, other)
        print(tostring(other.properties.collidable))
        if other.properties.collidable then
          return "slide"
        elseif other.properties.Player then
          return "cross"
        end
      end
The first if statement doesnt work and it prints out nil, Is there something Im doing wrong?

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

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 » Sat Apr 28, 2018 1:41 pm

Are you passing in the correct data to the function?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

KyleFlores1014
Citizen
Posts: 72
Joined: Thu May 25, 2017 1:43 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by KyleFlores1014 » Sat Apr 28, 2018 1:46 pm

Yes, the slide function works. Ive tried replacing "cross" with "slide" and it works. Im not sure why the collidable thing doesnt work.

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

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 » Sat Apr 28, 2018 2:20 pm

run other.properties through pairs and see what you get
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: Google [Bot] and 3 guests