Page 1 of 1

Help with making .love file

Posted: Tue Aug 11, 2009 10:52 pm
by Smileyforall
Hello just found out about this engine and am excited to use it! Anyways I was going through the first tutorial and am having trouble with making a .love file work. Whenever I drag and drop onto the love icon I get the outlines for a new window and then nothing. I do not understand where the graphics go as well. Thank you in advance.

Re: Help with making .love file

Posted: Tue Aug 11, 2009 11:00 pm
by Robin
A .love file is actually a .zip file, which contains main.lua, other lua files, game.conf and your images etc. The beautiful thing about LÖVE is you can use folders as .love files as well.

See http://love2d.org/forum/viewtopic.php?f=4&t=451 for more details.

Re: Help with making .love file

Posted: Wed Aug 12, 2009 12:17 am
by Smileyforall
Have another question will just keep it in this thread so as to avoid clutter. I just made two .gifs for directions in which the person is facing based on left or right. Now does anyone have any idea on how to make it so that pressing left would remove the right facing picture and put in the left facing picture and vice versa? Sorry, am very new, thanks in advance.

Re: Help with making .love file

Posted: Wed Aug 12, 2009 3:45 am
by Person
There is no need to remove the old picture, every time Löve runs your code, it erases the picture currently drawn on the screen. So when you write...

love.graphics.draw( mypic, 0, 0 )

in your draw() function, all it really is doing is drawing the mypic many times a second, so it looks like one continuous picture.

In order to change what picture is drawn to the screen you need to check what is happening with the keyboard. The Löve documentation has a great call back for the keyboard, see it here.

http://love2d.org/docs/keypressed.html

Check for whether or not the left or right arrow key is pressed in the update(dt) function and change a variable to show this change. An example would be if the left arrow key is pressed...

function keypressed(key)
if key == love.key_left then
lastkey = "left"
end
end

Then check in the draw() function what the last key was and draw accordingly..

if lastkey == "left" then
love.graphics.draw( mypicleft, 0, 0 )
end

I'll leave how to figure out the right key up to you but it's pretty straightforward.
Have fun! :nyu:

Re: Help with making .love file

Posted: Wed Aug 12, 2009 4:06 am
by Smileyforall
Thx man will check into that, I'm looking in from a graphics perspective and have never done coding before so it takes me a little bit :)

Re: Help with making .love file

Posted: Thu Aug 13, 2009 2:51 am
by Smileyforall
I guess my question is how to have two images loaded into it, but only have one come out when a key pressed. Sorry I am really struggling with this.

Re: Help with making .love file

Posted: Thu Aug 13, 2009 4:51 am
by TechnoCat
Here are two ways to do it.

This changes the horizontal scale from 1 to -1. If you turn the image into an animation it actually flips it about the center.

Code: Select all

function load()
	megaman=love.graphics.newImage("mmstand.png")
	x=200
	dir=1
end

function update(dt)

	if love.keyboard.isDown(love.key_right) then
		x=x+100*dt
		dir=-1
	elseif love.keyboard.isDown(love.key_left) then
		x=x-100*dt
		dir=1
	end

end

function draw()

	love.graphics.draw(megaman,x,100,0,dir,1)
	
end
This loads two separate images for left and right.

Code: Select all

function load()
	megamanl=love.graphics.newImage("mmstandl.png")
	megamanr=love.graphics.newImage("mmstandr.png")
	megamandir=megamanl
	x=200
end

function update(dt)

	if love.keyboard.isDown(love.key_right) then
		x=x+100*dt
		megamandir=megamanr
	elseif love.keyboard.isDown(love.key_left) then
		x=x-100*dt
		megamandir=megamanl
	end

end

function draw()

	love.graphics.draw(megamandir,x,100)
	
end

Posted: Thu Aug 13, 2009 3:42 pm
by Smileyforall
Thanks man that explains it very well.