trail is a LÖVE library that... generates trails, you guessed it!
local trail = require "trail" --require the library
Create new trail
function love.load()
myTrail = trail:new({
type = "mesh",
content = {
source = love.graphics.newImage("image.png"),
width = 26,
mode = "stretch"
},
duration = .4
})
myTrail:setMotion(600, 0)
myTrail:setPosition(x, y)
end
Update library
function love.update(dt)
trail:update(dt)
end
Draw trail
function love.draw()
myTrail:draw()
end
settings = {
type,
content = {}, --depends on trail type
duration,
amount,
fade
}
Point
settings = {
type = "point",
content = {
--
type = "image",
source,
--
type = "rectangle",
width,
height,
--
type = "circle",
radius
--
},
fade --"shrink" or "grow"
}
Mesh
settings = {
type = "mesh",
content = {
source, --image
width,
mode
}
}
Methods can be chained.
myTrail:setPosition(...):setMotion(...)
Update trails
trail:update(dt)
--or update each trail separately
myTrail:update(dt)
Draw trail
--affected by love.graphics.setColor
myTrail:draw()
Create trail
myTrail = trail:new(settings)
Set trail position
myTrail:setPosition(x, y)
Set trail motion
myTrail:setMotion(x, y, vx, vy)
Set trail width (mesh)
myTrail:setWidth(width)
Enable/disable trail
myTrail:enable()
myTrail:disable()
myTrail:toggle()
Thanks to Spyro and Taehl for their work on trail meshes.