Page 1 of 1
Images?
Posted: Tue Nov 30, 2010 9:08 pm
by God Awakened
The Wiki isn't a very strong source...
Code: Select all
function love.draw()
function newPaddedImage(filename)
local source = love.image.newImageData(filename)
local w, h = source:getWidth(), source:getHeight()
-- Find closest power-of-two.
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
-- Only pad if needed:
if wp ~= w or hp ~= h then
local padded = love.image.newImageData(wp, hp)
padded:paste(source, 0, 0)
return love.graphics.newImage(padded)
end
return love.graphics.newImage(source)
end
newPaddedImage("C:/Documents and Settings/Nanny/Desktop/Beau/JesUnlimited/Header.gif")
end
It keeps saying that it can't load the GIF file.
Re: Images?
Posted: Tue Nov 30, 2010 9:21 pm
by God Awakened
New:
Code: Select all
function love.draw()
function newPaddedImage(filename)
local source = love.image.newImageData(filename)
local w, h = source:getWidth(), source:getHeight()
-- Find closest power-of-two.
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
-- Only pad if needed:
if wp ~= w or hp ~= h then
local padded = love.image.newImageData(wp, hp)
padded:paste(source, 0, 0)
return love.graphics.newImage(padded)
end
return love.graphics.newImage(source)
end
newPaddedImage("HEADER.gif")
end
The problem is that the window shows, but the image doesn't.
Re: Images?
Posted: Tue Nov 30, 2010 9:38 pm
by Robin
That's not... how it works at all.
Example how it could work:
Code: Select all
function newPaddedImage(filename)
local source = love.image.newImageData(filename)
local w, h = source:getWidth(), source:getHeight()
-- Find closest power-of-two.
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
-- Only pad if needed:
if wp ~= w or hp ~= h then
local padded = love.image.newImageData(wp, hp)
padded:paste(source, 0, 0)
return love.graphics.newImage(padded)
end
return love.graphics.newImage(source)
end
function love.load()
header = newPaddedImage("HEADER.gif")
end
function love.draw()
love.graphics.draw(header, 0, 0)
end
Do you know Lua? It's pretty vital to know that for LÖVE, and not that hard to learn.
Re: Images?
Posted: Wed Dec 01, 2010 10:01 pm
by God Awakened
I've been programming Lua for 3 years...
O.o
And thanks.
It's just that I'm new to LOVE.
Re: Images?
Posted: Wed Dec 01, 2010 10:56 pm
by Robin
Oh, OK. I'm sorry I assumed you were a rookie in Lua.
Then the thing you probably didn't know is that love.draw() is called every frame, which would create a new closure every frame, and that images are objects you need to keep around and draw yourself, because LÖVE can't know what you want to draw, when you want to draw it, where you want to draw it, etc.
I'm sure you'll find the wiki most useful if you just keep on browsing. If you haven't already, you might want to check out the tutorials.
Re: Images?
Posted: Thu Dec 02, 2010 1:06 am
by zac352
Uh... Have you not used Lua in a while, or has Lua changed some syntax here...
Last time I tried declaring a function like this:
Code: Select all
function blargh()
function localrand()
return 4; --xkcd reference ftw
end
print(localrand())
end
barfed errors all over my console. You should do this:
Code: Select all
function blargh()
localrand=function()
return 4; --xkcd reference ftw
end
print(localrand())
end
:S
Re: Images?
Posted: Thu Dec 02, 2010 5:41 am
by Mud
zac352 wrote:Lua changed some syntax here...
It has.
Re: Images?
Posted: Thu Dec 02, 2010 12:35 pm
by zac352
Mud wrote:zac352 wrote:Lua changed some syntax here...
It has.
Kay. I thought I might be going a little crazy.
Re: Images?
Posted: Thu Dec 02, 2010 4:44 pm
by Robin
zac352 wrote:Uh... Have you not used Lua in a while, or has Lua changed some syntax here...
What version of Lua are you using? It works fine in 5.1.4. Also note that in both cases "localrand" is actually a global.
Re: Images?
Posted: Thu Dec 02, 2010 8:50 pm
by zac352
Robin wrote:zac352 wrote:Uh... Have you not used Lua in a while, or has Lua changed some syntax here...
What version of Lua are you using? It works fine in 5.1.4. Also note that in both cases "localrand" is actually a global.
Idk. I think I tested it in Lua 4.0... I had some old LuaEdit that I got from download.com...
I knew that. :S
I just left it out (AKA forgot).