gurkenlabs / litiengine

LITIENGINE 🕹 The pure 2D java game engine.
https://litiengine.com/
MIT License
725 stars 93 forks source link

TileLayer.finish() adds every tile to tileList twice #472

Closed Hades948 closed 1 year ago

Hades948 commented 1 year ago

Describe the bug TileList.finish() passes this.getData() to the constructor of a CopyOnWriteArrayList. This copies all of the tiles into tileList. The for loop in this function also adds every tile to the list with tileList.add().

Stack Trace No error for this bug.

To Reproduce Steps to reproduce the behavior:

  1. Load a map
  2. Call map.getTileLayers() to get a collection of the map's layers
  3. Call layer.getTiles().size() on one of the layers. Result: the size is twice the expected size.

Expected behavior I would expect layer.getTiles().size() to return the map's tileWidth * tileHeight.

Screenshots In my particular case, I'm adding collision boxes based on tile IDs. Because I was using layer.getTiles() to retrieve all of the tiles, my code was adding every collision box twice: image

Your System:

Additional context Looks like this is the commit that added this bug: https://github.com/gurkenlabs/litiengine/commit/4cfe6edddef1deafe1bf64d35bd8531b17332ea2

github-actions[bot] commented 1 year ago

Thank you for your reporting your first LITIENGINE issue! We are looking forward to your further contributions.