What is Lope2D?
Lope2D (Love2D Physics Engine) - Library (set of functions and other stuff) that makes it easier to work with physical bodies. It also makes your code much more clean.
Why Lope2D can be useful if I develop a game with gameplay based on physics.
To add one physical body in the game (using standard set of functions of Love2D), you would have to write 7-8 lines, and if needed to draw a sprite (plus one line):
Code: Select all
function love.load()
world = love.physics.newWorld(320,0,true)
love.physics.setMeter(32)
object = {}
object.image = love.graphics.newImage(“object.png”)
object.shape = love.physics.newRectangleShape(50, 50)
object.body = love.physics.newBody(world, 100, 100, “dynamic”)
object.fixture = love.physics.newFixture(object.body, object.shape, 100)
end
function love.update(dt)
world:update(dt)
end
function love.load()
love.graphics.draw(object.image, object.body:getX(), object.body:getY(), object.body:getAngle(), 1, 1, object.image:getWidth()/2, object.image:getHeight()/2)
end
To add the same dynamic body using Lope2D, you will need make like this:
Code: Select all
function love.load()
image_object = love.graphics.newImage("object.png")
object = lope_newDynamic(100, 100, "rectangle", 50, 50)
lope_setImage(object, image_object)
end
function love.update(dt)
lope_update(dt)
end
function love.draw()
lope_drawWorld()
end
More details about adding physical bodies you will learn in the next tutorials.
How can I get it? How can I get started using Lope2D?
To use Lope2D, you need to download two files:
lope_core.lua
lope_graphics.lua
http://bitbucket.org/erlimoen/lope2d/src
After that you need to put them in the one folder with your "main.lua" file and add this code in its beginning:
Code: Select all
require "lope_core"
Other tutorials soon...