Code: Select all
world:update(dt)
for _, shape in ipairs(deleteMe) do --deleteMe is an array that has shapes to be deleted
shape:destroy()
end
Code: Select all
world:update(dt)
for _, shape in ipairs(deleteMe) do --deleteMe is an array that has shapes to be deleted
shape:destroy()
end
Code: Select all
world:update(dt)
for _, shape in ipairs(deleteMe) do
shape:destroy()
end
-- use the code in this loop for every shape that needs to be destroy
for _, shape in ipairs(shapesToBeDestroyed) do
shape:setMask(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
table.insert(deleteMe, shape)
end
I think it is possible although it depends on WHEN you are trying to destroy the particular shape.v1rr3n wrote:it doesn't work and love2d crashes. My question is: Is it possible to remove just one shape from a body given love2d's problem with shape:destroy()?
A simple approach would be not to destroy the sensor at all.v1rr3n wrote:So I don't know what I'm going to do. Anyone have a suggestion as to how to do a physical attack?
Did you look at any of the code apart from the setMask bit? The code has a one frame delay, because it shifts the shapes needing to be deleted after checking if anything is ready to be deleted. The action flow might go like this:v1rr3n wrote:I tried the setMask and the result is the same. I wanted to attach a sensor to a body that already has a non-sensor shape. The sensor would only appear when a key is pressed and disappear when released (created and destroyed). Basically it is simulating a punch or melee attack. I can't seem to get destroy to work and my deadline approaches . One solution is I can perhaps set the sensor inside of the other shape and when a key is pressed set the sensor outside the other shape where the punch needs to be. I'll try that instead. I just hope that when I get to destroying the baddies things go easier. After all, I can set them outside of any collisions and handle them that way hopefully.
Edit: I don't know if I can set the position of a body once it is attached. So I don't know what I'm going to do. Anyone have a suggestion as to how to do a physical attack?
Is it acceptable to use shape mask to skip collision instead of destroying the shape? Basically, the shape you mask is instructed to avoid other shape having the mentioned category. So, instead of destroying it, you 'hide' it. Moreover, the graphical representation/animation could be adjusted according to the active mask of each shape.v1rr3n wrote:The sensor would only appear when a key is pressed and disappear when released (created and destroyed). Basically it is simulating a punch or melee attack.
No worries.v1rr3n wrote:Thanks I went back and revisited the problem and I wasn't emptying the table every time I was deleting a shape. I appreciate the help Ivan and Blackbullet.
Users browsing this forum: Ahrefs [Bot] and 5 guests