- My map has a Spawn Point layer with a Player object in it.
- I have a sprite.png image in the same directory as main.lua and it's being properly set to the sprite variable.
- My Sprites Layer is properly being assigned, is set to visible, and has the player property assigned correctly.
- I put a debug print statement in the layer.draw function, but it never seems to fire. My Spawn Point object layer also doesn't seem to appear even when I remove the map:removeLayer("Spawn Point") line.
Any help would be greatly appreciated here. Full contents of my main.lua below.
Code: Select all
local sti = require "lib.sti.sti"
local inspect = require "inspect"
function love.load()
-- Load map file
map = sti("magecity.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
print("\nPlayer\n")
print(inspect(player))
-- Create player object
local sprite = love.graphics.newImage("sprite.png")
layer.player = {
sprite = sprite,
x = player.x,
y = player.y,
ox = sprite:getWidth() / 2,
oy = sprite:getHeight() / 1.35
}
print("\nLayer\n")
print(inspect(layer))
-- 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
)
print("Drawing Sprites layer!")
-- 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("Spawn Point")
end
function love.update(dt)
-- Update world
map:update(dt)
end
function love.draw()
-- Draw world
map:draw()
end