Load Atlas and Font images from paths
This commit is contained in:
parent
886ad221a0
commit
7604a23824
|
@ -6,12 +6,14 @@ local Object = require "lib/classic"
|
|||
local Atlas = Object:extend()
|
||||
|
||||
---Creates a new atlas.
|
||||
---@param image love.Image The source image for the atlas.
|
||||
---@param image_path string The path to the source image for the atlas.
|
||||
---@param sw integer The width of each sprite.
|
||||
---@param sh integer The height of each sprite.
|
||||
---@param ax integer? The anchor X coordinate of each sprite. Defaults to 0.
|
||||
---@param ay integer? The anchor Y coordinate of each sprite. Defaults to 0.
|
||||
function Atlas:new(image, sw, sh, ax, ay)
|
||||
function Atlas:new(image_path, sw, sh, ax, ay)
|
||||
local image = love.graphics.newImage(image_path)
|
||||
|
||||
---The source image of the atlas.
|
||||
self.image = image
|
||||
|
||||
|
|
8
font.lua
8
font.lua
|
@ -5,12 +5,12 @@ local Atlas = require "atlas"
|
|||
local Font = Atlas:extend()
|
||||
|
||||
---Creates a new font.
|
||||
---@param image love.Image The source image for the atlas.
|
||||
---@param image_path string The path to the source image for the atlas.
|
||||
---@param sw integer The width of each sprite.
|
||||
---@param sh integer The height of each sprite.
|
||||
---@param characters string[] A list of characters with indices corresponding to each sprite.
|
||||
function Font:new(image, sw, sh, characters)
|
||||
Font.super.new(self, image, sw, sh)
|
||||
function Font:new(image_path, sw, sh, characters)
|
||||
Font.super.new(self, image_path, sw, sh)
|
||||
|
||||
---A map of characters to sprites.
|
||||
self.characters = {}
|
||||
|
@ -32,7 +32,7 @@ function Font:draw(text, x, y)
|
|||
local sprite = self.characters[c]
|
||||
if sprite then
|
||||
local x = (i - 1) * self.sw + x
|
||||
Font.super.draw(self, sprite, x, y)
|
||||
self.super.draw(self, sprite, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
6
main.lua
6
main.lua
|
@ -17,8 +17,6 @@ local pushOpts = {
|
|||
push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, pushOpts)
|
||||
|
||||
function love.load()
|
||||
local blockyFont = love.graphics.newImage("assets/small-blocky-font.png")
|
||||
|
||||
local blockFontChars = {
|
||||
" ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "×", "+", ",", "-", ".", "/", --first line
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", --second line
|
||||
|
@ -28,9 +26,9 @@ function love.load()
|
|||
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "{", "|", "}", "~", --fourth line
|
||||
}
|
||||
|
||||
BlockyFont = Font(blockyFont, 8, 8, blockFontChars)
|
||||
BlockyFont = Font("assets/small-blocky-font.png", 8, 8, blockFontChars)
|
||||
|
||||
local uiAtlas = Atlas(love.graphics.newImage("assets/flat-ui.png"), 32, 32)
|
||||
local uiAtlas = Atlas("assets/flat-ui.png", 32, 32)
|
||||
|
||||
Window = NineSlice(uiAtlas, {
|
||||
tl = 26,
|
||||
|
|
|
@ -11,8 +11,8 @@ local function rowState(atlas, row, len, on_finish, next)
|
|||
return spannedState(atlas, start, len, on_finish, next)
|
||||
end
|
||||
|
||||
local leafRanger = Atlas(love.graphics.newImage("assets/leaf-ranger.png"), 288, 128, 144, 128)
|
||||
local bringerOfDeath = Atlas(love.graphics.newImage("assets/bringer-of-death.png"), 140, 93, 105, 93)
|
||||
local leafRanger = Atlas("assets/leaf-ranger.png", 288, 128, 144, 128)
|
||||
local bringerOfDeath = Atlas("assets/bringer-of-death.png", 140, 93, 105, 93)
|
||||
|
||||
return {
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue