How do I delete an object in 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
NewbiePeta
Prole
Posts: 6
Joined: Sat Sep 28, 2024 3:52 pm

How do I delete an object in bump?

Post by NewbiePeta »

I have code like this that adds objects from my table to world:add

Code: Select all

function addBlock(x,y,w,h)
    local block = {x=x, y=y, w=w, h=h}
	blocks[#blocks+1] = block
	world:add(block, x,y,w,h)
end
And like this when adding

Code: Select all

for i, v in ipairs(net) do
		if net[i][3] == true then
			addBlock(net[i][1]-sizeCell, net[i][2], sizeCell, sizeCell)
		end
	end
And in this case, how can I remove a collision of an object when, for example, a bullet hits it and I checked it through the CheckCollisions function
User avatar
pgimeno
Party member
Posts: 3710
Joined: Sun Oct 18, 2015 2:58 pm

Re: How do I delete an object in bump?

Post by pgimeno »

Not sure without being able to see the rest of your code, but, maybe you can filter out collisions using, well, a filter?
RNavega
Party member
Posts: 457
Joined: Sun Aug 16, 2020 1:28 pm

Re: How do I delete an object in bump?

Post by RNavega »

I think they mean destroying the object.
In the bump API, the counterpart to world:add() seems to be world:remove().

https://github.com/kikito/bump.lua?tab= ... -the-world
NewbiePeta
Prole
Posts: 6
Joined: Sat Sep 28, 2024 3:52 pm

Re: How do I delete an object in bump?

Post by NewbiePeta »

this is understandable, I just don't understand which item to delete. in other words, world:remove(item). For example, blocks[1] does not work
User avatar
dusoft
Party member
Posts: 765
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How do I delete an object in bump?

Post by dusoft »

Well, then blocks[1] index is nil / does not exist.

You can use something like https://gist.github.com/nrk/31175 to print out your blocks table and see its detailed structure including indexes.
You would be better of using pairs instead of ipairs to traverse if you have gaps in your table.

Also: use table.insert for adding elements instead of using its last index #+1.
RNavega
Party member
Posts: 457
Joined: Sun Aug 16, 2020 1:28 pm

Re: How do I delete an object in bump?

Post by RNavega »

I don't use bump, but if I understand your question, the library tells you exactly what items that collided. One is the item being used with the world:move() function, you already know that item since you're the one calling that function with it.

The other items are all the collided items in the 'cols' table that's returned from it.

Each index of cols (if len > 0, meaning if there were any collisions) has a 'other' key that points to the other item in the collision. That's the item you use with :remove().
If you're testing the player for collisions, and the other item happens to be a bullet, then remove that 'other' and add damage to the player: https://github.com/kikito/bump.lua?tab= ... resolution
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests