I'm not entirely sure why this is happening. Here's the code for loading and updating, although it's still rather messy:
Loading:
Code: Select all
map = sti.new('assets/maps/test_map')
map:addCustomLayer('Sprite Layer', 4)
lp.setMeter(32)
world = lp.newWorld(0, 1000)
collision = map:initWorldCollision(world)
sprite_layer = map.layers['Sprite Layer']
sprite_layer.sprites = {
player = Player.new(100, 37 * 32, 32, 32, 0, 6, 6, true, 4, 0, 20000, 'right')
}
player = sprite_layer.sprites.player
player.body = lp.newBody(world, player.x, player.y, 'dynamic')
player.shape = lp.newRectangleShape(13 * 6, 24 * 6)
player.fixture = lp.newFixture(player.body, player.shape)
player.body:setLinearDamping(5)
player.body:setFixedRotation(true)
translate_x = math_floor(-player.x + window_width / 2 - player.width - 16)
translate_y = math_floor(-player.y + window_height / 2 - player.height - 16)
function sprite_layer:update(dt)
for _, sprite in pairs(self.sprites) do
Player.update(dt)
end
end
function sprite_layer:draw()
for _, sprite in pairs(self.sprites) do
Player.draw()
end
end
Code: Select all
world:update(dt)
translate_x = math_floor(-player.x + window_width / 2 - player.width - 16)
translate_y = math_floor(-player.y + window_height / 2 - player.height - 16)
local x, y = 0, 0
if lk.isDown("w") or lk.isDown("up") then y = y - player.speed end
if lk.isDown("s") or lk.isDown("down") then y = y + player.speed end
if lk.isDown("a") or lk.isDown("left") then x = x - player.speed end
if lk.isDown("d") or lk.isDown("right") then x = x + player.speed end
player.body:applyForce(x, y)
player.x, player.y = player.body:getWorldCenter()
map:update(dt)
If anyone could help me out with an explanation and solution to this problem, I'd appreciate it. I updated STI not even two days ago, and STI hasn't been updated in a few months, so I'm definitely up to date.
Thanks!