Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by airstruck »

I hope love.graphics.line is next :)
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Zireael »

Karai, thanks for the help :)
Scottbert
Prole
Posts: 4
Joined: Thu Sep 08, 2016 11:19 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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?
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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(
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
Scottbert
Prole
Posts: 4
Joined: Thu Sep 08, 2016 11:19 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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?
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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.
Scottbert
Prole
Posts: 4
Joined: Thu Sep 08, 2016 11:19 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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".
Last edited by Karai17 on Fri Sep 09, 2016 9:50 am, edited 1 time in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by Karai17 »

I poked Etaine on Twitter, she's gonna accept my PRs soon, so hopefully this issue is resolved from hence forth.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Scottbert
Prole
Posts: 4
Joined: Thu Sep 08, 2016 11:19 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests