Drawing images in another script?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Drawing images in another script?
So I have a bit of a problem when I use "function love.draw ()" in a script other than my main one. I use "require("scriptname")" to load that script but when I use the draw function it draws the things from that script only, with a black screen covering up everything from my main.lua file. How can I draw from another script without it messing up everything else?
Re: Drawing images in another script?
If I understand, you want to define several 'love.draw' functions : it can't work, the last defined override the others.
You must have only one 'love.draw' (in main.lua usually) that call other functions defined in your modules.
You must have only one 'love.draw' (in main.lua usually) that call other functions defined in your modules.
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: Drawing images in another script?
I think he needs gamestates instead of multiple love functions.
Try having a different "draw" function instead of using multiple love.draw functions in each file you're requiring. For example:
And if you want to call one of the draw functions, you can have a global gamestate variable:
To use the gamestate variable in love.draw to call one of the draw functions, you can do:
That concept can be used for the love.update(dt) (file1_update(dt), file2_update(dt), file3_update(dt)) as well.
Hope it helps!
Edit: Fixed a typo in my code.
Try having a different "draw" function instead of using multiple love.draw functions in each file you're requiring. For example:
Code: Select all
-- file1
function file1_draw()
end
-- file2
function file2_draw()
end
-- file3
function file3_draw()
end
Code: Select all
-- in love.load()
gamestate = "n/a"
Code: Select all
-- in love.draw
if gamestate == "file1" then
file1_draw()
elseif gamestate == "file2" then
file2_draw()
elseif gamestate == "file3" then
file3_draw()
end
Hope it helps!
Edit: Fixed a typo in my code.
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 62 guests