Floating

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.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Floating

Post by zac352 »

JRascall wrote:as if firefox would need to download the web page you're looking 60 times a second.
Yeah, okay.
It takes me half a minute to 10 minutes to load one page. :roll:
JRascall wrote:Sorry, but am coming from a (limited) C# and XNA background and never used a draw function.
Ok well Ill work on it follow some tutorials or somin thing, any way thanks.
Why is it that all you microsoft/adobe folks always have trouble with the idea that computers operate on an iterative cycle? :o:
Hello, I am not dead.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Floating

Post by Ryne »

zac352 wrote:
JRascall wrote:as if firefox would need to download the web page you're looking 60 times a second.
Yeah, okay.
It takes me half a minute to 10 minutes to load one page. :roll:
JRascall wrote:Sorry, but am coming from a (limited) C# and XNA background and never used a draw function.
Ok well Ill work on it follow some tutorials or somin thing, any way thanks.
Why is it that all you microsoft/adobe folks always have trouble with the idea that computers operate on an iterative cycle? :o:
No need to be rude. I'm glad you didn't reply to many of my issues, I might have had some harsh replies to send back.
@rynesaur
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Floating

Post by tentus »

zac352 wrote:Why is it that all you microsoft/adobe folks always have trouble with the idea that computers operate on an iterative cycle? :o:
Hey, I'm an MS/Adobe guy and I understand iteration. Quit with the generalizations, it only serves to chase people away.
Kurosuke needs beta testers
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Floating

Post by kikito »

JRascall wrote:I get that but is text only static? or does text have to be images for em to move?
Hi JRascall,

Here's what LÖVE does, very briefly, when it starts executing your game:

Code: Select all

love.load()
love.update(dt)
<erase screen>
love.draw()
love.update(dt)
<erase screen>
love.draw()
love.update(dt)
<erase screen>
love.draw()
...
It goes on an on until you force the exit.

'dt' indicates how much time has passed since the last call to love.update. It changes from computer to computer. So must use it for movement-related stuff.

In LÖVE there are no "Windows" or "buttons" or "labels" to move around. Text is just 'a list characters stored in memory'.

There're also a couple functions that you can use (inside love.draw) for rendering text on the screen. You can tell these functions where you want the text to appear, but there's no 'Label class' that holds the string and the coordinates together. You have to store that in variables you manage yourself.

You have to:
  • create the variables you need in love.load. For example, variables that hold your text x,y coordinates.
  • update the variables in love.update. Perhaps modifying the coordinates a little, using dt. Maybe using math.sin
  • Draw the text inside on love.draw, using the variables you created in love.load and have been updating in love.update
I hope this helps.
When I write def I mean function.
JRascall
Prole
Posts: 8
Joined: Fri Dec 03, 2010 9:12 pm

Re: Floating

Post by JRascall »

Thanks for that, Its helped me out alot, any chance you would know how make a floaty effect so its constantly moving, am guessing using a loop?
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Floating

Post by Ryne »

JRascall wrote:Thanks for that, Its helped me out alot, any chance you would know how make a floaty effect so its constantly moving, am guessing using a loop?
Wait, what EXACTLY are you trying to do? I'm wondering why you want text to be constantly moving.
Last edited by Ryne on Sat Dec 04, 2010 2:30 am, edited 1 time in total.
@rynesaur
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Floating

Post by zac352 »

tentus wrote:
zac352 wrote:Why is it that all you microsoft/adobe folks always have trouble with the idea that computers operate on an iterative cycle? :o:
Hey, I'm an MS/Adobe guy and I understand iteration. Quit with the generalizations, it only serves to chase people away.
Sorry, but I have to at least seen 5 of these threads so far about not understanding iterative rendering cycles.
I never really realised that it'd be a difficult thing to understand, as it simply clicked for me while I was learning Lua. I really never thought about it until I came here... :roll:

This place is really difficult, because it propagates hurdles that I have never encountered before... It really makes you feel like an alien or a robot or something. :?

This is probably my oldest unedited script I can find:

Code: Select all

tri1={{1,0},{1,1},{0,0}}
point={.25,.25}

c=0
for i=1,3 do
pointb=tri[i]
pointc=tri[i+1<4 and i+1 or 1]
pointa={point[1]-pointb[1],point[2]-pointb[2]}
pointx={pointc[1]-pointb[1],pointc[2]-pointb[2]}
rot=AngleFromSlope(pointx[1],pointx[2])
rot2=AngleFromSlope(pointa[1],pointa[2])
if rot2-rot>0 and rot2-rot<180 then
c=c+1;
end
end
if c==3 then
print("Collision")
else
print("No collision")
end
It's my first attempt at collision detection ever. It took me weeks to figure out the math for it, and I eventually discovered that it doesn't work. I believe AngleFromSlope was my old function I used before figuring out what math.atan2 does.
JRascall wrote:Thanks for that, Its helped me out alot, any chance you would know how make a floaty effect so its constantly moving, am guessing using a loop?
If you have the numbers stored in a value in memory, you can modify those values in love.update each frame to change the position of the window relative to each time reference. I recommend multiplying the update value by dt to keep it moving at a constant rate, though. ;)

Here's an example:

Code: Select all

function love.load()
	myPrettyBox={ --declare our pretty box to draw on screen
		x=0;
		y=0;
		w=200;
		h=100;
	}
end

function love.update(dt)
	myPrettyBox.x=myPrettyBox.x + 50*dt --move it to the right by 50 pixels every second.
	myPrettyBox.y=myPrettyBox.y + myPrettyBox.y*dt --double position every second
end

function love.draw()
	love.graphics.setBackgroundColor(255,255,255) --Set the bg to white
	love.graphics.setColor(0,255,0) --myPrettyBox will be a lovely green
	love.graphics.rectangle(
		"fill",			--Draw it filled with beautiful colour
		myPrettyBox.x,	--x position
		myPrettyBox.y,	--y position
		myPrettyBox.w,	--width
		myPrettyBox.h	--height
	)
end
Edit: There seemed to be more comments while editing that in gedit... :roll:
Hello, I am not dead.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Floating

Post by bartbes »

JRascall wrote:Thanks for that, Its helped me out alot, any chance you would know how make a floaty effect so its constantly moving, am guessing using a loop?
Well, you could change the code from this:

Code: Select all

love.graphics.print("My Text", 400, 300)
(yes that's example code)

Code: Select all

love.graphics.print("My Moving text", 400+math.random()*2-1, 300+math.random()*2-1)
It will randomly move within 2 pixels (the *2, and the -1 is to make it range from -1 to 1).
Post Reply

Who is online

Users browsing this forum: No registered users and 65 guests