Error whit loading sprites

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Matema
Prole
Posts: 1
Joined: Sun Mar 02, 2025 6:57 pm

Error whit loading sprites

Post by Matema »

This is the file game.lua:

Code: Select all

local game = {}
local gravity = 100
local score = 0

function game:load()
    arrow = {
        Arrowx = 380,
        Arrowy = 490,
        arrow1 = love.graphics.newImage("assets\arrow.png")
    }
    --enemy = {}
    love.graphics.setBackgroundColor(0, 0, 0)
    love.graphics.setDefaultFilter("nearest", "nearest")
    enemyx = love.math.random(0, 770)--mettere sempre 770
    enemyy = 60 --mettere sempre 60
    enemy.sprite = love.graphics.newImage('assets/blocktest.png')
end

function game:update(dt)
    if love.keyboard.isDown("d") then
        arrowx = arrowx + 10
    end
    if love.keyboard.isDown("a") then
        arrowx = arrowx - 10
    end
end

function game:draw()
    love.graphics.setLineWidth(5)    
    love.graphics.line(0, 540, 800, 540)
    love.graphics.line(0, 480, 800, 480) 
    --love.graphics.polygon("fill", 400, 540, 410, 520, 390, 520)
    love.graphics.draw(arrow.arrow1, arrow.Arrowx, arrow.Arrowy, 0, 2.5, 2.5)
    --love.graphics.draw(enemy, enemyx, enemyy, 0, 1, 1)
   -- love.graphics.print(score, 0, 80)
end

return game
This is the other file menu.lua:

Code: Select all

local menu = {}
local font = love.graphics.newFont("assets/PressStart2P-Regular.ttf", 50)
local Delta = "ΔDelta"
local Start = "Start"
local Exit = "Exit"
local Game = require("game")

function menu.draw()
    love.graphics.setFont(font)
    love.graphics.print(Delta, 0, 300)
    love.graphics.print(Start, 0, 400)
    love.graphics.print(Exit, 0, 500)
end

function menu.keyreleased(key)
        if key == "w" then
            Start = "• Start"
            Exit = "Exit"
        end
        if key == "s" then
            Exit = "• Exit"
            Start = "Start"
        end
        if key == "return" then
            if Start == "• Start" then
                function love.load()
                    Game.load()
                end
                function love.draw()
                    Game.draw()
                end
            end
            if Exit == "• Exit" then
                love.event.quit()
            end
        end
end

return menu
The final file called main.lua:

Code: Select all

function love.load()
    Menu = require("menu")
    Game = require("game")
end

function love.draw()
    Menu.draw()
end

function love.keyreleased(key)
    Menu.keyreleased(key)
end
This is the error that gives me:
Image
Attachments
Screenshot 2025-03-02 200004.png
Screenshot 2025-03-02 200004.png (20.87 KiB) Viewed 102 times
User avatar
dusoft
Party member
Posts: 745
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Error whit loading sprites

Post by dusoft »

Weird naming conventions with lowercase/uppercase, but I would suspect the game:load is not run on load... Test with printing a message or similar debug.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests