my approach last time (i didn't used any library for the physics though) was to give each game object an offx and offy fields so that they had an x and y field for where start to draw and a collision box = {self.x + self.offx, self.y + self.offy, self.w - 2 * self.offx, self.h - 2 * self.offy} (and it worked!)
but this time (using bump) sprites keep sinking in the ground;
anyone mind help me with this?
EDIT: wait, i think the problem lies in:
Code: Select all
local goal_x = self.x + self.dx * dt
local goal_y = self.y + self.dy * dt
local cols -- using strict.lua
self.x, self.y, cols = self.world:move(self, goal_x, goal_y, self.filter)
--
here some (i guess) related code:
Code: Select all
function Skeleton:new(x, y)
self.super.new(self, x, y)
self.id = "enemy"
self.w = 16
self.h = 15
self.offy = 1
self.animations = {
walk = anim8.newAnimation(self.grid("1-10", 2), 0.055)
}
self.current_animation = "walk"
self.spd = 50
self.moving = true
self.dir = -1
self.world:add(self, self:get_rect())
self.filter = function(item, other)
if other.id == "player" or other.id == "phantom" then
return "cross"
else
return "slide"
end
end
end
Code: Select all
function Entity:get_rect()
return self.x + self.offx, self.y + self.offy, self.w - self.offx * 2, self.h - self.offy
end
Code: Select all
function Entity:draw()
love.graphics.setColor(255, 255, 255, 100)
love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
love.graphics.setColor(255, 0, 0, 100)
love.graphics.rectangle("fill", self.x + self.offx, self.y + self.offy, self.w, self.h)
self.animations[self.current_animation]:draw(self.img, self.x, self.y, 0, self.dir, 1, self.dir == -1 and self.w or 0)
end