Hey guys. I discovered Löve last night and started making my first ever videogame, with my 10 year old as designer (that's him shooting lasers from his eyes). I'm sure I'll have a lot of questions in the days to come. Thanks in advance, and thanks for making Love.
RE: Particle System
I love the particle systems and want to use them everywhere, but I noticed they don't have a destroy method, like Body and Shape. Are they garbage collected? If I just keep calling newParticleSystem will I go OOM?
I was paranoid about that and wrote some code to cache particle systems and reuse them when "not ps:isActive() and ps:isEmpty()". This works great unless I call setSprite on one of the recycled systems, at which point Love crashes. If it turns out I do need to recycle these, does anyone know why setSprite would cause a crash?
RE: Audio
If I try to play my 1 second laser sound 3 times in a second, only the first call actually plays. It seems if I want N instances of a sound playing simultaneously, I need N instances of that audio source (even though it's the same file). Is that correct?
RE: Physics
I made a bunch of boxes and drop them into a contained space, and they behave pretty much like you would expect. But if I change newRectangleShape to newCircleShape, the bodies fall straight through my floor and/or get stuck in it. Am I doing it wrong?
Newbie questions (re: particles, physics, audio)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Newbie questions (re: particles, physics, audio)
Last edited by Mud on Fri Nov 05, 2010 8:58 pm, edited 1 time in total.
Re: Newbie questions (re: particles, physics, audio)
Wow.. I've actually never used any of those libraries thus far.
When I tried using physics, it crashed love. When I tried particles, I got errors that made no sense (even after copying and pasting directly from the demo ). I'm not even going to attempt audio until the time comes.
When I tried using physics, it crashed love. When I tried particles, I got errors that made no sense (even after copying and pasting directly from the demo ). I'm not even going to attempt audio until the time comes.
Hello, I am not dead.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Newbie questions (re: particles, physics, audio)
That was epicly funny.Mud wrote:(that's him shooting lasers from his eyes)
Everything is, bodies and shapes as well, the destroy methods are there because you may very well want the objects to be gone right at that instant, instead of existing until the next garbage collection cycle.Mud wrote:I love the particle systems and want to use them everywhere, but I noticed they don't have a destroy method, like Body and Shape. Are they garbage collected?
It is, I've got a simple sound manager here.Mud wrote:f I try to play my 1 second laser sound 3 times in a second, only the first call actually plays. It seems if I want N instances of a sound playing simultaneously, I need N instances of that audio source (even though it's the same file). Is that correct?
Re: Newbie questions (re: particles, physics, audio)
That's kinda funny. I was drawn to the things that would look the coolest with the least effort from me.zac352 wrote:Wow.. I've actually never used any of those libraries thus far.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Newbie questions (re: particles, physics, audio)
As I have never used those, I'll skip right to:Mud wrote:RE: Particle System
Yes: these are Sources, which is like a physical source of sound. If you want more than one "copy" of the sound, you use more sources.Mud wrote:RE: Audio
If I try to play my 1 second laser sound 3 times in a second, only the first call actually plays. It seems if I want N instances of a sound playing simultaneously, I need N instances of that audio source (even though it's the same file). Is that correct?
Hm, odd. Hard to say if you're doing it wrong. If you supplied the .love in which it goes wrong, we might be able to help you further.Mud wrote:RE: Physics
I made a bunch of boxes and drop them into a contained space, and they behave pretty much like you would expect. But if I change newRectangleShape to newCircleShape, the bodies fall straight through my floor and/or get stuck in it. Am I doing it wrong?
EDIT: really? Ninja'd thrice?
Help us help you: attach a .love.
Re: Newbie questions (re: particles, physics, audio)
Your youtube video is haunted. First, it somehow crashed FF. Then it gave me an error message. Now it says 401 unauthorised. Now it crashed again.
Hello, I am not dead.
Re: Newbie questions (re: particles, physics, audio)
OK, I'll try to strip it down to the small code that reproduces the problem.Robin wrote:If you supplied the .love in which it goes wrong, we might be able to help you further.
Cool. So I just need to keep a reference around, to prevent something from being collected while in use, right?bartbes wrote:Everything is, bodies and shapes as well
So I'll just create particle systems willy nilly, keep a reference to them, then remove the reference when "not ps:isActive() and ps:isEmpty()".
Excellent. One thing I noticed in your code:bartbes wrote:I've got a simple sound manager here.
Code: Select all
--check which sounds in the queue have finished, and remove them
local removelist = {}
for i, v in ipairs(self.queue) do
if v:isStopped() then
table.insert(removelist, i)
end
end
--we can't remove them in the loop, so use another loop
for i, v in ipairs(removelist) do
table.remove(self.queue, v-i+1)
end
Code: Select all
for #self.queue,1,-1 do
if self.queue[i]:isStopped() then
table.remove(self.queue, i)
end
end
Code: Select all
local raw = {}
function sound_load(name, filename)
raw[name] = love.sound.newSoundData(filename)
end
function sound_play(name)
love.audio.play(love.audio.newSource(raw[name], 'static'))
end
With those assumptions in mind, my KISS sound code is currently:
Code: Select all
local rawdata = {}
local sources = {} -- reference sources so they aren't collected while in use
function sound_load(name, filename)
rawdata[name] = love.sound.newSoundData(filename)
end
function sound_play(name)
local source = love.audio.newSource(rawdata[name], 'static')
sources[#sources + 1] = source
love.audio.play(source)
end
function sound_update()
for i=#sources,1,-1 do
if sources[i]:isStopped() then
table.remove(sources, i)
end
end
end
Re: Newbie questions (re: particles, physics, audio)
tryMud wrote:Code: Select all
function sound_play(name) local source = love.audio.newSource(rawdata[name], 'static') sources[#sources + 1] = source love.audio.play(source) end
Code: Select all
function sound_play(name)
sources[#sources + 1] = love.audio.newSource(rawdata[name], 'static')
love.audio.play(sources[#sources])
end
Re: Newbie questions (re: particles, physics, audio)
Thanks for the tip, but I tend to prefer simpler lines over fewer lines. In this case, the extra line eliminates a redundant table lookup and call to the length operator.thelinx wrote:tryCode: Select all
function sound_play(name) sources[#sources + 1] = love.audio.newSource(rawdata[name], 'static') love.audio.play(sources[#sources]) end
Re: Newbie questions (re: particles, physics, audio)
So glad I happened to stumble on this, I was having problems with my audio earlier today and this fixed it up. The only problem I have with the sound manager is that it's absolutely terrible for large files (because it loads the whole file into memory and decodes it.) Using this for my background music mp3 was a no-go, which was fine because it was one of the few things I wasn't having a problem with. That said, using this for small sound-effects is perfect.
Also, welcome to the community, Mud!
Ninwa
Also, welcome to the community, Mud!
Ninwa
Who is online
Users browsing this forum: No registered users and 92 guests