Page 57 of 92

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Wed Sep 07, 2016 11:58 pm
by airstruck
I hope love.graphics.line is next :)

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Thu Sep 08, 2016 7:04 am
by Zireael
Karai, thanks for the help :)

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Thu Sep 08, 2016 11:22 pm
by Scottbert
Hello! I am new to Lua and Love, and am attempting to follow the tutorial provided here: http://lua.space/gamedev/using-tiled-maps-in-love

I've dropped the sti folder into the same directory as main.lua, and written the most basic of main.luas as suggested in the tutorial:

Code: Select all

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

function love.load()
      -- Load map file
    map = sti.new("democave.lua")
end

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

function love.draw()
    -- Draw world
    map:draw()
end
But love just halts with an error:

Code: Select all

Program starting as '"C:\Love\love.exe" "J:\dev\demo" -debug'.
Program 'love.exe' started in 'J:\dev\demo' (pid: 19608).
Error: main.lua:6: attempt to call field 'new' (a nil value)
stack traceback:
	main.lua:6: in function 'load'
	[string "boot.lua"]:439: in function <[string "boot.lua"]:435>
	[C]: in function 'xpcall'
Program completed in 69.39 seconds (pid: 19608).
What am I doing wrong?

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 1:38 am
by CrackedP0t
Scottbert wrote:Hello! I am new to Lua and Love, and am attempting to follow the tutorial provided here: http://lua.space/gamedev/using-tiled-maps-in-love

I've dropped the sti folder into the same directory as main.lua, and written the most basic of main.luas as suggested in the tutorial:

Code: Select all

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

function love.load()
      -- Load map file
    map = sti.new("democave.lua")
end

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

function love.draw()
    -- Draw world
    map:draw()
end
But love just halts with an error:

Code: Select all

Program starting as '"C:\Love\love.exe" "J:\dev\demo" -debug'.
Program 'love.exe' started in 'J:\dev\demo' (pid: 19608).
Error: main.lua:6: attempt to call field 'new' (a nil value)
stack traceback:
	main.lua:6: in function 'load'
	[string "boot.lua"]:439: in function <[string "boot.lua"]:435>
	[C]: in function 'xpcall'
Program completed in 69.39 seconds (pid: 19608).
What am I doing wrong?
replace sti.new( with sti(

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 3:03 am
by Scottbert
Thank you!

...But now the player sprite doesn't display. I copied everything exactly, except for the filename of the player sprite (which is right because it gives me an error if it's wrong) and the name of the object layer in the file (I called it 'Objects' instead of 'Spawn Point' in Tiled)

Code: Select all

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

function love.load()
      -- Load map file
    map = sti("democave.lua")
    
    -- Create new dynamic data layer called "Sprites" as the 8th layer
    local layer = map:addCustomLayer("Sprites", 8)

    -- 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("img/playerstatic.png")
    layer.player = {
        sprite = sprite,
        x      = player.x,
        y      = player.y,
        ox     = sprite:getWidth() / 2,
        oy     = sprite:getHeight() / 1.35
    }

    -- 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
        )

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


    -- Remove unneeded object layer
    map:removeLayer("Objects")

end

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

function love.draw()
    -- Draw world
    map:draw()

end

The map displays, but it does not place the Player. What am I doing wrong now?

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 9:15 am
by Zireael
How many layers do you have, Scottbert? Might be you're running into the same issue I had - count your layers and add the sprites after them, so if you have 2 layers you make sprites the 3rd.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 9:30 am
by Scottbert
Zireael wrote:How many layers do you have, Scottbert? Might be you're running into the same issue I had - count your layers and add the sprites after them, so if you have 2 layers you make sprites the 3rd.
Yup! Now the player draws, but I get this...

Code: Select all

Error: main.lua:46: attempt to call field 'point' (a nil value)
I had to comment out the lines for drawing the point to make it run. This tutorial is terrible! Is there one that actually gives working code for me to examine?

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 9:33 am
by Karai17
I tried to have the article updated but the pr was never accepted.

As for your issue, change "love.graphics.point" to "love.graphics.points".

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 9:49 am
by Karai17
I poked Etaine on Twitter, she's gonna accept my PRs soon, so hopefully this issue is resolved from hence forth.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Sep 09, 2016 8:03 pm
by Scottbert
Karai17 wrote:I tried to have the article updated but the pr was never accepted.
Ah, so STI updated and broke old code, but you weren't allowed to update the tutorial? That sucks. If that doesn't work out, maybe post an updated tutorial elsewhere?
Thank you for the tutorial, hopefully after I'll be far enough to learn more on my own and get coding!