Re: Simple Tiled Implementation - STI v0.16.0.3
Posted: Wed Sep 07, 2016 11:58 pm
I hope love.graphics.line is next
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
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).
replace sti.new( with sti(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:But love just halts with an error: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
What am I doing wrong?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).
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
Yup! Now the player draws, but I get this...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.
Code: Select all
Error: main.lua:46: attempt to call field 'point' (a nil value)
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?Karai17 wrote:I tried to have the article updated but the pr was never accepted.