Page 1 of 1

Shapes & particle systems or how to create a player trail

Posted: Fri May 30, 2014 8:30 am
by Rostiger
Hello all!

I'm fairly new to LÖVE and just started learning Lua in the past couple of days using the Wiki and searching the forums. So far I've got a few things going that I'm happy with but finally bumped into a topic I can't find a solution for.

Currently all I've got is a circle moving towards the mouse cursor and making a kind of dashing movement when pressing the right mouse button.
Now I'd like to add a little trail to the circle when dashing and can't find a proper solution.

The most straight forward approach would be to use a particle system, but it seems like I need to load an image to be able to display something. So far I'm just using the draw function to display basic shapes and I'd like to keep it that way for now, especially since I might want to change the radius of my player circle later on and I like the aesthetic of basic geometry. So my first question is:

Is it possible to use shapes like rectangles, circles, etc. in particle systems?
I've tried something like this, but it just throws an error (can the circle function only be called from within the draw function?):

Code: Select all

g = love.graphics
circle = g.circle( "fill", player.x, player.y, player.radius )
player.trail = g.newParticleSystem(circle, 5)
My other idea was to basically code the particle system myself, storing coordinates in an array (which are called tables in Lua, right? I haven't grasped that part of Lua yet), creating a circle object at the stored coordinate and slowly fading it out. But that seems overly complicated and I need to learn a couple more concepts about arrays and OOP before pursuing this method.

Isn't there a simple way to create a player trail?
I've attached my current script in case you are interested.

Thanks for taking the time and helping out a n00b. :)

Re: Shapes & particle systems or how to create a player trai

Posted: Tue Jun 03, 2014 7:09 pm
by DrCicero
if newParticleSystem really needs to be passed an image/canvas, so create one!

Code: Select all

local circle = g.newCanvas(player.radius, player.radius)

g.setCanvas(circle)
g.circle( "fill", player.radius/2, player.radius/2, player.radius)

g.setCanvas()
player.trail = g.newParticleSystem(circle, 5)
This code was not tested.

Documentation of newCanvas