(probably) simple particle system questions:

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.
Post Reply
mml
Prole
Posts: 2
Joined: Wed Feb 26, 2025 7:31 pm

(probably) simple particle system questions:

Post by mml »

I'm working on enhancing the arkanoid clone tutorial, and have decided what it really needs is for the blocks to emit showers of sparks, which a particlesystem seems the obvious choice, but have run into a perplexing issue.

the way i've implemented it, if a brick is hit, a pre-initialized particle system is cloned and stored in a table for drawing/updating in the usual callbacks. the position is set to the position of the block that was hit, via setPosition(). in the update and draw process, update is called on each stored particlesystem, and the draw calls are made for each as usual.

What I'm seeing, is everything behaving normally, *except* that the particle emitter seems to be displayed doing its thing at some random coordinates down and to the right of the coordinates I have setPosition() on. upon examination of empty emitters prior to removal, their position is set as expected.

1. what might be going on here?
2. should I be cloning particle systems like that?



Image
mml
Prole
Posts: 2
Joined: Wed Feb 26, 2025 7:31 pm

Re: (probably) simple particle system questions:

Post by mml »

Code: Select all

local v = require "hump/vector"
local bricks = {}
--- ...
bricks.current_bricks = {}
local ps = love.graphics.newParticleSystem(love.graphics.newImage("media/img/idx.png"), 32)
ps:setParticleLifetime(2, 2)
ps:setLinearAcceleration(-5, -5, 50, 100)
ps:setColors(255, 255, 255, 255, 255, 255, 255, 0)
local colors = {
-- color map ...
}
local emits = {} -- emitter storage
function bricks.draw()
  for _, brick in pairs(bricks.current_bricks) do --draw remaining bricks
    bricks.draw_brick(brick)
  end
  for _, em in pairs(emits) do --iterate through the emitters
    local x, y = em:getPosition()
    love.graphics.circle("line", x, y, 10, 16) --draw a circle where I think they are
    love.graphics.draw(em, x, y) --draw emitter 
  end
end

function bricks.hit(brick) -- called externally when a brick is hit, 
                                       -- passing in a brick struct, after which the brick is removed from current_bricks
                                       -- this is done b/c the brick in question is about to go away
  local p = ps:clone() -- clone preconfigured particlesystem
  p:setPosition(brick.ctr.x, brick.ctr.y) --set its position
  ps:start() -- start the particlesystem
  p:emit(32) -- have it start spitting out some sparks
  table.insert(emits, p) -- store this clone in the emits list
end

function bricks.new_brick(pos, bricktype, dim)
  -- no interaction w/ the particlesystem, just creates new brick structs
end

function bricks.draw_brick(brick)
  love.graphics.push("all")
  -- draw the bricks
  love.graphics.pop()
end

function bricks.update(dt)
  if #bricks.current_bricks == 0 then
    bricks.no_more_bricks = true
  end
-- even if there are no bricks, there are probably some emitters live still...
  for i, em in pairs(emits) do. --iterate through list of emitters
    if em:getCount() == 0 then --if the emitter is empty, stop & null it out
      em:stop()
      emits[i] = nil
    else
      em:update(dt). --update live emitters
    end
  end
end

function bricks.add_to_current_bricks(brick)
  -- no interaction w/ particle system, just appends brick structs to bricks storage
end

function bricks.construct_level(level_bricks_arrangement)
  -- sets up level etc, no particlsysteminteraction
end

return bricks

Last edited by mml on Wed Feb 26, 2025 10:13 pm, edited 1 time in total.
RNavega
Party member
Posts: 457
Joined: Sun Aug 16, 2020 1:28 pm

Re: (probably) simple particle system questions:

Post by RNavega »

Things that I'd do to debug this problem, if I were in your position:
  • Trying different acceleration values. So not (-5, -5, 50, 100) but rather (-1, -1, 1, 1), then (-10, -10, 10, 10) and others.
  • Sanity check: can I emit particles from wherever I want at all? Like emitting particles from the mouse position, flawlessly? If I can't even do that then I know there's something messed up.
  • Trying different particle sprites. Like a 10x10 px rectangle, then a 32x32 px rectangle etc. Do they look okay, is there any display state affecting the proper drawing of particles?
PS I'd also try coming up with a different way of drawing bricks that didn't involve a graphics.push / graphics.pop pair on each individual brick. Certainly you could do the same by keeping a Transform object for each brick, and then using that as the input in graphics.draw?
That is:

Code: Select all

local brick_tfs = {}
brick_tfs[1] = love.math.newTransform(...)
-- Using the Transform to supply the coordinates for this specific brick:
love.graphics.draw(my_brick_image, brick_tfs[1])
You can then move the bricks by manipulating the Transform of each, like translating, rotating etc, or overwriting it entirely through :setTransformation().
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 6 guests