Won't display text and image

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Incognita177
Prole
Posts: 2
Joined: Thu Jun 30, 2022 5:22 am

Won't display text and image

Post by Incognita177 »

I've been trying to get this to work for so long, and I almost did but for some reason every time I run it only the picture shows up and not the text. When I put the code for the image in a comment, the text shows up, but when I un-comment the image code the text disappears and only the image shows. here's my code:

function love.draw()
love.graphics.print("Welcome to the game!", 0, 0)
end

local dog = love.graphics.newImage('dog.png')

function love.load()
love.graphics.setDefaultFilter('nearest', 'nearest')
end

function love.draw()
love.graphics.draw(dog, 300, 400)
end
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Won't display text and image

Post by ReFreezed »

You can't have two love.draw functions. The latter replaces the previous one. Put all your rendering code in the same function.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: Won't display text and image

Post by GVovkiv »

As ReFrezzed mentioned, put your drawable in single love.draw function.
Like here:

Code: Select all

local dog = love.graphics.newImage('dog.png')

function love.load()
    love.graphics.setDefaultFilter('nearest', 'nearest')
end

function love.draw()
    love.graphics.draw(dog, 300, 400)
    love.graphics.print("Welcome to the game!", 0, 0)
end
Incognita177
Prole
Posts: 2
Joined: Thu Jun 30, 2022 5:22 am

Re: Won't display text and image

Post by Incognita177 »

Thank you so much! The text and picture are both displaying now!
Post Reply

Who is online

Users browsing this forum: baconhawka7x, Google [Bot] and 44 guests