Shapes & particle systems or how to create a player trail

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
Rostiger
Prole
Posts: 1
Joined: Fri May 30, 2014 8:12 am

Shapes & particle systems or how to create a player trail

Post 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. :)
Attachments
main.lua
(2.38 KiB) Downloaded 111 times
User avatar
DrCicero
Prole
Posts: 19
Joined: Sun Jun 01, 2014 8:56 pm
Location: Germany

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

Post 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
Xeldas Saga - my ca. 10min action-platformer (contains sound effects, music, graphics and a boss fight)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests