Hi there,
i have small problem, i haven't found any solution for it so i am asking you.
Is there way to draw image outside love.draw() or any command to call love.draw() inside any other "event"?
Drawing image outside love.draw()
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 4
- Joined: Fri Jul 15, 2011 10:45 pm
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Drawing image outside love.draw()
The way this is done is by setting variables in love.update() and have love.draw() draw certain images and other graphics, based on those variables.
Help us help you: attach a .love.
-
- Prole
- Posts: 4
- Joined: Fri Jul 15, 2011 10:45 pm
Re: Drawing image outside love.draw()
I wanted to draw loading image in loop (while the game is loading), thanks anyway.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Drawing image outside love.draw()
If you really want that, you have two options:
- Load a bit of whatever you're loading, stop to draw things, resume loading, repeat.
- Do the same, but load things in a separate thread.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Drawing image outside love.draw()
I've been wanting to do a "resource loader" that allowed for automating that for a while now. But it's on my TODO list.sevcik.daniel wrote:I wanted to draw loading image in loop (while the game is loading), thanks anyway.
In the meantime, the first thing you need to know when you are programming in LÖVE is that you'll be better of if your code works "with" the love.callbacks, instead of "against" or "around" them.
The easiest way of doing what you want working with LÖVE is:
- Loading the actual images inside love.update instead of love.load and
- Using a variable inside love.draw and love.update to know when you are "loading the game images" and when you are "done loading images, and just showing the real game"
Code: Select all
function love.load()
loadingImage = love.graphics.load("loading.png")
imageNames = { 'player', 'enemy' }
images = {}
loadedImagesCount = 0
gameState = "loading"
player = {x=100, y=100}
enemy = {x=300, y=300}
end
function love.draw()
if gameState == "loading" then
love.graphics.draw(loadingImage, 200, 200)
else -- game is in "normal" state
love.graphics.draw(images.player, player.x, player.y)
love.graphics.draw(images.enemy, enemy.x, enemy.y)
end
end
function love.update(dt)
if gameState == "loading" then
local imageName = imageNames[loadedImagesCount + 1]
images[imageName] = love.graphics.newImage( imageName .. ".png" )
loadedImagesCount = loadedImagesCount + 1
if loadedImagesCount >= #imageNames then loading = false end
else
-- move the player and enemy coordinates around using dt
end
end
If your love.update and love.draw functions start getting too big, divide them in smaller ones (i.e. drawLoading() ).
Also, a small self-plug: I've developed a couple libs that might interest you to handle this complexity; but you will likely need to learn more stuff before being able to use them properly. For now, just know there are libs out there that might help.
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests