Code: Select all
--main.lua
require "level1" ; require "level2"
function love.load()
love.physics.setMeter(64)
world = love.physics.newWorld(0,9.81*64, true)
--[...]
level = 1
if level == 1 then load_level1(world)
elseif level == 2 then unload_level1() ; load_level2(world) end
end
function love.draw()
if level == 1 then draw_level1()
elseif level == 2 then draw_level2() end
end
function love.update()
--my code
end
Code: Select all
--level1.lua
function load_level1(world)
obj1 = {}
obj1.body = love.physics.newBody(world, 111,111, "dynamic")
obj1.shape = love.physics.newRectangleShape(28,28)
obj1.fixture = love.physics.newFixture(obj1.body,obj1.shape)
end
function unload_level1()
obj1 = nil
end
function draw_level1()
love.graphics.polygon("line", obj1.body:getWorldPoints(obj1.shape:getPoints()))
end
The problem is that I can't check the level variable in the love.load() function because it's called just one time. Is there another solution ?