[SOLVED] sync sprites with collision boxes using bump

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

[SOLVED] sync sprites with collision boxes using bump

Post by Lirija »

Hi guys, i'm having some problems with syncing collision boxes with sprites using bump:

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)

maybe i should add self.offx to goal_x and self.offy to goal_y
--

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
some more..

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
and Entity:draw() just in the case

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
Last edited by Lirija on Tue Jun 19, 2018 7:26 am, edited 1 time in total.
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Re: sync sprites with collision boxes using bump

Post by Lirija »

Ok it was stupid i should have offset the sprite instead of the collision box in the first place ^^
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 100 guests