Page 75 of 92

Re: Simple Tiled Implementation - STI

Posted: Wed Feb 14, 2018 11:52 pm
by Marty
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.

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Thu Feb 15, 2018 12:38 pm
by Karai17
Cool, I look forward to it. :)

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Sun Feb 18, 2018 1:00 pm
by Saoskia
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 :)

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Thu Apr 19, 2018 1:09 pm
by Stargazer
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?

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Thu Apr 19, 2018 9:59 pm
by Karai17
You need to add ".lua" to the end of your file name.

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Fri Apr 20, 2018 6:18 pm
by Stargazer
Thanks!

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Sat Apr 28, 2018 1:38 pm
by KyleFlores1014
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?

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Sat Apr 28, 2018 1:41 pm
by Karai17
Are you passing in the correct data to the function?

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Sat Apr 28, 2018 1:46 pm
by KyleFlores1014
Yes, the slide function works. Ive tried replacing "cross" with "slide" and it works. Im not sure why the collidable thing doesnt work.

Re: Simple Tiled Implementation - STI v0.18.2.1

Posted: Sat Apr 28, 2018 2:20 pm
by Karai17
run other.properties through pairs and see what you get