Watch the stars fly!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Watch the stars fly!

Post by Kingdaro »

Mud wrote:
Kingdaro wrote:I'm much more comfortable with using for i=1, #table [..] I never really bothered to get the concept of pairs/ipairs
Iterating arrays that way can be faster (eliminating iterator function call overhead), but only if you index the table you're iterating no more than ~1-2 times in the loop body, and it only works for arrays. For instance:

Code: Select all

for i=1, #stars do
   stars[i].y = stars[i].y+(speed*dt*(stars[i].size/2))
end

for i,star in ipairs(stars) do
   star.y = star.y+(speed*dt*(star.size/2))
end
The second loop is faster, because we eliminate 3 table look-ups, which saves more time than we lose from the iterator call (I also find it easier to read).

Code: Select all

for i=1, #stars do
   local star = stars[i]
   star.y = star.y+(speed*dt*(star.size/2))
end
That would work for me.
Mud wrote:
Kingdaro wrote:here's the demo in all it's beautified and updated glory. (See first post.)
The line "star.x = math.random(-640,1280)" is generating ~65% of your stars off-screen where they will never be seen.
That's part of the new feature I plan to add where you can move your mouse around the starfield to move around the starfield, per-say.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Watch the stars fly!

Post by bartbes »

Also, note that ipairs might get deprecated in lua 5.2.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Watch the stars fly!

Post by Kingdaro »

bartbes wrote:Also, note that ipairs might get deprecated in lua 5.2.
inb4peoplegoingape<censored>

It's kind of funny how this tiny little gadget got more attention than my other much bigger project.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Watch the stars fly!

Post by thelinx »

bartbes wrote:Also, note that ipairs might get deprecated in lua 5.2.
Actually, they changed their minds. ipairs is staying.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Watch the stars fly!

Post by Kingdaro »

thelinx wrote:
bartbes wrote:Also, note that ipairs might get deprecated in lua 5.2.
Actually, they changed their minds. ipairs is staying.
Okay that's good. I might consider using it one day, maybe not today. :)
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Watch the stars fly!

Post by thelinx »

There's nothing wrong with using for 1,#table do instead of ipairs(table).
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Re: Watch the stars fly!

Post by arquivista »

thelinx wrote:
bartbes wrote:Also, note that ipairs might get deprecated in lua 5.2.
Actually, they changed their minds. ipairs is staying.
It's a good call, Love people use so much ipairs than a lot of programs had to be revised (or use old Loves) just to use new Love versions with new Lua.
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Watch the stars fly!

Post by zac352 »

I'm not sure if anyone noticed this, but HOURS? Minutes seems to better fit there. :?
Hello, I am not dead.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Watch the stars fly!

Post by Kingdaro »

zac352 wrote:I'm not sure if anyone noticed this, but HOURS? Minutes seems to better fit there. :?
Explain further.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Watch the stars fly!

Post by TechnoCat »

Kingdaro wrote:
zac352 wrote:I'm not sure if anyone noticed this, but HOURS? Minutes seems to better fit there. :?
Explain further.
He is just being an arrogant fool.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], baconhawka7x, Google [Bot] and 58 guests