[library] Moving objects on paths (alpha)
Posted: Sat Mar 26, 2016 11:46 pm
Yep, no need to mess with Xes and Ys. This library allows you to set a path and let your object or character move across it with ease.
Currently this alpha version supports:
Usage Note:
Simply download the library and add it to your project file, add the line: to your main.lua file at the very top.
Then proceed to create an object for the path, and use the newPath function to create a new path, setMovement to prepare the movement and follow to follow it. Such as
You can use newPath as following: To define a line use two parameters (x,y), if you want to create an arc, you can use ('arc',x,y,width,flipped) which makes the whole syntax something like this:
x1,y1 is the starting position of the path, every other x,y is the end point of either an arc or a line, width is how high the arc should be (the distance between the pinpoint of the arc and the midpoint between the start point of the arc and the end point), flipped is either true or false, decides the direction to set the arc. You can mess around with them, better documentary coming with the beta version.
Upcoming and planned features includes
Currently this alpha version supports:
- Setting a continuous path and setting an object to loop it.
- shapes includes: lines and arcs
- Doesn't break even if the delta time increases significantly
- Expand path on the fly.
- Draw the path
Usage Note:
Simply download the library and add it to your project file, add the line:
Code: Select all
require 'path'
Then proceed to create an object for the path, and use the newPath function to create a new path, setMovement to prepare the movement and follow to follow it. Such as
Code: Select all
require 'path'
function love.load()
path1=newPath(3,2,6,2,8,4,'arc',7,5,.1,false,'arc',6,5,.5,true,6,7,'arc',3,7,3,true,'arc',3,2,7,false)
path1:setMovement(5,true)
end
function love.update(dt)
path1:follow(dt)
end
function love.draw()
love.graphics.scale(40)
love.graphics.setLineWidth(0.05)
love.graphics.circle('fill', path1.x,path1.y,.25)
for i = 0,20,1 do
love.graphics.line(0,i,50,i)
love.graphics.line(i,0,i,50)
end
love.graphics.setColor(255,0,0)
path1:draw()
love.graphics.setColor(255,255,255)
--you only need path1:draw(), but the rest helps with the example
--also adds grid lines.
end
Code: Select all
newPath(x1,y1,x,y,x,y,'arc',x,y,width,flipped,x,y,x,y)
Upcoming and planned features includes
- Multiple objects on the same path (top priority)
- Acceleration and Deceleration support.
- More shapes, suggest ideas and needs.
- General optimizations and cleaner code for clarity.