Watch the stars fly!
Watch the stars fly!
A little somethin' I decided to whip up in a couple hours.
Last edited by Kingdaro on Mon Nov 22, 2010 8:26 pm, edited 1 time in total.
- 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!
Hi! That remember more snow fall than stars but is always a nice effect. Look, shouldn't be a Mac issue but it seems that from time to time things stop a bit. Let's wait for other reports to see if it's only happening here. Also stars animation/trail isn't quite smooth. Probably something could be improved. Keep the good work in this demo!Kingdaro wrote:A little somethin' I decided to whip up in a couple hours.
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
Re: Watch the stars fly!
Thanks for the feedback.arquivista wrote:Hi! That remember more snow fall than stars but is always a nice effect. Look, shouldn't be a Mac issue but it seems that from time to time things stop a bit. Let's wait for other reports to see if it's only happening here. Also stars animation/trail isn't quite smooth. Probably something could be improved. Keep the good work in this demo!Kingdaro wrote:A little somethin' I decided to whip up in a couple hours.
I plan to add a stars counter at the top of the screen (already did) and I want to make it more customizable, like setting speed or color or image or direction, etc.
From the stars counter I concluded that the game gets slower/laggier because of the amount of stars in the game constantly increasing. Here's my part of the script to fix it, and what came up when I tried to do this. The chunk added in is surrounded by comment brackets, and the number sign is where the error occurred, according to the blue screen of death.
Code: Select all
stars = {}
time = 1
function love.update(dt)
if math.random(1,2) == 2 then
local star = {}
star.x = math.random(0,640)
star.y = -100
star.size = math.random(0.4,2.5)
table.insert(stars,star)
end
for i=1, #stars do
if stars[i] ~= nil then
stars[i].y = stars[i].y+(150*dt*stars[i].size)
end
end
--[[
for i=1, #stars do
if stars[i].y >= 480 then --#main.lua.24 attempt to index field ? (a nil value)
table.remove(stars,i)
end
end
--]]
if time >= 1 then
love.graphics.setCaption("Watch the stars fly! ("..love.timer.getFPS().." FPS)")
time = 0
else
time = time+dt
end
end
Re: Watch the stars fly!
Here's an attempt at using the particle system for a star field (move mouse around to 'turn'):
Code: Select all
local stars, center
function love.load()
center = {
x = love.graphics.getWidth()/2,
y = love.graphics.getHeight()/2,
}
stars = love.graphics.newParticleSystem( love.graphics.newImage('fire.png'), 300 )
stars:setPosition(center.x, center.y)
stars:setBufferSize( 2000 )
stars:setEmissionRate( 300 )
stars:setLifetime( -1 )
stars:setParticleLife( 6 )
stars:setColor( 55, 55, 55, 0, 255, 255, 255, 255 )
stars:setSize( 0.16, 0.1, 1 )
stars:setSpeed( 30, 80 )
stars:setSpread( math.rad(360) )
stars:setRadialAcceleration( 20 )
end
function love.keypressed(key)
if key == 'escape' then os.exit() end
end
function love.update(dt)
local x, y = love.mouse.getPosition()
stars:setOffset((x-center.x) * -5, (y-center.y) * -5)
stars:update(dt)
end
function love.draw()
love.graphics.draw(stars, 0, 0)
end
- Attachments
-
- stars.love
- (1.54 KiB) Downloaded 220 times
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Watch the stars fly!
Code: Select all
love.graphics.draw(love.graphics.newImage("star.png"),stars[i].x,stars[i].y,0,stars[i].size/4)
Create the image only once!
for instance, look in love.load and love.draw for stars.image:
Code: Select all
math.randomseed( os.time() )
function love.load()
win = love.graphics.setMode(640,480)
stars = {}
time = 1
stars.image = love.graphics.newImage("star.png")
f = love.graphics.newFont(12)
love.graphics.setFont(f)
end
function love.update(dt)
if math.random(1,2) == 2 then
local star = {}
star.x = math.random(0,640)
star.y = -128
star.size = math.random(0.5,2)
table.insert(stars,star)
end
for i,star in ipairs(stars) do
if star.y < 480 then
star.y = star.y+(150*dt*star.size)
else
table.remove(stars,i)
end
end
if time >= 1 then
love.graphics.setCaption("Watch the stars fly! ("..love.timer.getFPS().." FPS)")
time = 0
else
time = time+dt
end
end
function love.draw()
for _,star in ipairs(stars) do
love.graphics.draw(stars.image,star.x,star.y,0,star.size/4)
end
end
Code: Select all
if math.random(1,2) == 2 then
local star = {}
star.x = math.random(0,640)
star.y = -40
star.size = math.random(0.5,2)
table.insert(stars,star)
end
Simply making it something like
Code: Select all
if math.random(1,2) == 2 and time>=1 then
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Watch the stars fly!
I fully support this nonononono.TechnoCat wrote:nononononoCode: Select all
love.graphics.draw(love.graphics.newImage("star.png"),stars[i].x,stars[i].y,0,stars[i].size/4)
EDIT: fixed misquote
Last edited by kikito on Mon Nov 22, 2010 1:08 pm, edited 2 times in total.
When I write def I mean function.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Watch the stars fly!
I support the nonononono, but I don't support the misquote.
Help us help you: attach a .love.
Re: Watch the stars fly!
Yeaarquivista wrote:Hi! That remember more snow fall than stars but is always a nice effect.Kingdaro wrote:A little somethin' I decided to whip up in a couple hours.
It is happening here too! You are not the only one...Look, shouldn't be a Mac issue but it seems that from time to time things stop a bit. Let's wait for other reports to see if it's only happening here.
It is well done Stay tuned (I hope the translations service of my choice choosed the right idiom )
Re: Watch the stars fly!
Thanks everyone for the ideas! The current state of the demo is excellent! I couldn't have done it without all your help.
Also, I'm much more comfortable with using for i=1, #table since it's what I've been using ever since I started using Lua and I never really bothered to get the concept of pairs/ipairs. (I'd rather not have anybody explain it to me. )
So, here's the demo in all it's beautified and updated glory. (See first post.)
Also, I'm much more comfortable with using for i=1, #table since it's what I've been using ever since I started using Lua and I never really bothered to get the concept of pairs/ipairs. (I'd rather not have anybody explain it to me. )
So, here's the demo in all it's beautified and updated glory. (See first post.)
Re: Watch the stars fly!
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:Kingdaro wrote:I'm much more comfortable with using for i=1, #table [..] I never really bothered to get the concept of pairs/ipairs
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 line "star.x = math.random(-640,1280)" is generating ~65% of your stars off-screen where they will never be seen.Kingdaro wrote:here's the demo in all it's beautified and updated glory. (See first post.)
Who is online
Users browsing this forum: Majestic-12 [Bot] and 1 guest