Images?

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
God Awakened
Prole
Posts: 3
Joined: Tue Nov 30, 2010 9:05 pm

Images?

Post 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.
God Awakened
Prole
Posts: 3
Joined: Tue Nov 30, 2010 9:05 pm

Re: Images?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Images?

Post 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.
Help us help you: attach a .love.
God Awakened
Prole
Posts: 3
Joined: Tue Nov 30, 2010 9:05 pm

Re: Images?

Post by God Awakened »

I've been programming Lua for 3 years...
O.o
And thanks.
It's just that I'm new to LOVE.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Images?

Post 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.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Images?

Post 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
Hello, I am not dead.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: Images?

Post by Mud »

zac352 wrote:Lua changed some syntax here...
It has.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Images?

Post by zac352 »

Mud wrote:
zac352 wrote:Lua changed some syntax here...
It has.
Kay. I thought I might be going a little crazy. :crazy:
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Images?

Post 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.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Images?

Post 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).
Hello, I am not dead.
Post Reply

Who is online

Users browsing this forum: No registered users and 202 guests