Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Entities Not Removed from Spatial Map After Destruction #441

Open
ArthurMbraga opened this issue Oct 9, 2024 · 0 comments
Open

bug: Entities Not Removed from Spatial Map After Destruction #441

ArthurMbraga opened this issue Oct 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ArthurMbraga
Copy link

Describe the bug

When an entity is destroyed, it is not removed from the spatial map, causing the destroyed entity to still be retrievable from its previous location and consuming memory.

Version

kaplay: 3001.0.0-beta.1

To Reproduce

  1. Create a level.
  2. Spawn a game object at location (0,0).
  3. Destroy this game object.
  4. Attempt to retrieve the object at location (0,0).
  5. The destroyed object is still returned.
kaplay();

loadSprite("grass", "/sprites/grass.png");

const level = addLevel([
    " =",
], {
    tileWidth: 64,
    tileHeight: 64,
    tiles: {
        "=": () => [
            sprite("grass"),
        ],
    },
});

const pos = vec2(0, 0)
level.spawn("=", pos)

wait(1, () => {
    const obj = level.getAt(pos)
    console.log(obj) 
    destroy(obj[0])
})

wait(2, () => {
    // shouldn't print the object
    const obj = level.getAt(pos)
    console.log(obj)
})

Expected behavior

When an entity is destroyed, it should be removed from the spatial map and should not be retrievable in step 5.

@ArthurMbraga ArthurMbraga added the bug Something isn't working label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant