New member here. I just went through the tutorials at sheepolution without much issue, but now I am working on a small project and am stuck relatively at the outset. I'm doing a simple single-screen platformer type game and am using the final sheepolution tutorial as a basis, but trying to also integrate the tilesheet tutorial from earlier on in the same tutorials and this is where I'm getting stuck. My player and box image/texture render fine, but none of the walls render, however collision with the walls works as expected (though they're invisible). Every thing I can think to print to console to debug and verify looks fine. I know I must be missing something, but just can't figure it out.
Here's the relevant code:
Code: Select all
-- main.lua
local tileSheet
local tileMap = {
{16,14,14,14,14,14,17, 1, 1,16,14,14,14,14,14,17},
{19, 0, 0, 0, 0, 0,18, 1, 1,19, 0, 0, 0, 0, 0,18},
{19, 0, 0, 0, 0, 0,11,14,14,12, 0, 0, 0, 0, 0,18},
{19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,18},
{21, 9, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9,22},
{ 1, 1,19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,18, 1, 1},
{ 1, 1,19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,18, 1, 1},
{16,14,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11,14,17},
{19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,18},
{19, 0, 0, 0, 0, 0, 6, 9, 9, 7, 0, 0, 0, 0, 0,18},
{19, 0, 0, 0, 0, 0,18, 1, 1,19, 0, 0, 0, 0, 0,18},
{21, 9, 9, 9, 9, 9,22, 1, 1,21, 9, 9, 9, 9, 9,22}
}
-- tables to contain collections of game entities
local objects, walls = {},{}
-- game entities
local player, box = {},{}
function love.load()
player = Player(100, 100)
box = Box(400, 150)
table.insert(objects, player)
table.insert(objects, box)
tileSheet = TileSheet("assets/tiles/laboratory.png", 64, 5, 5, 1, 1)
for y,v in ipairs(tileMap) do
for x,tile in ipairs(v) do
if tile > 0 then
table.insert(walls, Wall((x-1)*tileSheet:getTileWidth(), (y-1)*tileSheet:getTileHeight(), tileSheet, tile))
end
end
end
end
-- snip
-- drawing callback; called each frame after update()
function love.draw()
love.graphics.setBackgroundColor(0, 64, 128)
for i,v in ipairs(objects) do v:draw() end
for i,v in ipairs(walls) do v:draw() end
end
Code: Select all
-- TileSheet.lua
Object = require("lib.classic.classic")
TileSheet = Object:extend()
function TileSheet:new(imagePath, tileSize, sheetWidth, sheetHeight, tileGutter, tileScale)
self.texture = love.graphics.newImage(imagePath)
self.tileSize = tileSize
self.tileGutter = tileGutter or 0
self.tileScale = tileScale or 1
self.tileWidth = self.tileSize * self.tileScale
self.tileHeight = self.tileSize * self.tileScale
self.tileQuads = {}
-- build the tile sheet quads:
for y=0,(sheetHeight-1) do
for x=0,(sheetWidth-1) do
table.insert(self.tileQuads, love.graphics.newQuad((x*self.tileWidth)+(x*self.tileGutter), (y*self.tileHeight)+(y*self.tileGutter), self.tileWidth, self.tileHeight, self.texture:getWidth(), self.texture:getHeight()))
end
end
end
function TileSheet:getTexture() return self.texture end
function TileSheet:getTileWidth() return self.tileWidth end
function TileSheet:getTileHeight() return self.tileHeight end
function TileSheet:getTileQuad(tile) return self.tileQuads[tile] end
function TileSheet:getTileScale() return self.tileScale end
Code: Select all
-- TileSheetEntity.lua
require("entity")
require("TileSheet")
TileSheetEntity = Entity:extend()
function TileSheetEntity:new(x, y, tileSheet, tile)
TileSheetEntity.super.new(self, x, y)
self.tileSheet = tileSheet
self.tile = tile or 1
self.width = self.tileSheet:getTileWidth()
self.height = self.tileSheet:getTileHeight()
self.scale = self.tileSheet:getTileScale()
end
function TileSheetEntity:draw()
love.graphics.draw(self.tileSheet:getTexture(), self.tileSheet:getTileQuad(self.tile), (self.x-1)*self.width, (self.y-1)*self.height, 0, self.scale, self.scale)
end
Code: Select all
-- Wall.lua
require("TileSheetEntity")
Wall = TileSheetEntity:extend()
function Wall:new(x, y, tileSheet, tile)
Wall.super.new(self, x, y, tileSheet, tile)
self.strength = 100
self.weight = 0
--self.gravity = 0
end
function Wall:draw()
Wall.super.draw(self)
end
Thanks for looking and I hope someone out there can let me know what obvious thing I'm missing here.
I should mention that I am also new to lua, so it could equally be a lua language thing vs a love framework thing.