luxeengine / alpha

alpha - deprecated 2015~2016. unrelated to the new engine! view the new engine here - https://luxeengine.com/
MIT License
565 stars 74 forks source link

TilemapVisual; Changing a tiles id after display moves the tile above other tiles #360

Closed PentaHelix closed 8 years ago

PentaHelix commented 8 years ago
import luxe.Input;
import luxe.tilemaps.Tilemap;
import phoenix.Texture.ClampType;
import phoenix.Texture;
import luxe.Events;

class Main extends luxe.Game {
  var tilemap:Tilemap;

  override function ready() {
    tilemap = new Tilemap({
            x: 0,
            y: 0,
            w: 8,
            h: 8,
            tile_width: 16,
            tile_height: 16,
            orientation: TilemapOrientation.ortho,
        });

    Luxe.resources.texture("assets/tiles.png").filter_mag = FilterType.nearest;

    tilemap.add_tileset({
      tile_width: 16,
      tile_height: 16,
      texture: Luxe.resources.texture("assets/tiles.png"),
      name: "default",
      first_id: 0,
    });

    tilemap.add_layer({
      name: "one",
      visible: true,
      opacity: 1,
      layer: 1,
    });
    tilemap.add_layer({
      name: "two",
      visible: true,
      opacity: 1,
      layer: 2,
    });
    tilemap.add_layer({
      name: "three",
      visible: true,
      opacity: 1,
      layer: 3,
    });

    tilemap.add_tiles_fill_by_id("one",1);
    tilemap.add_tiles_fill_by_id("two",0);
    tilemap.add_tiles_fill_by_id("three", 2);

    tilemap.tile_at("three", 0, 0).id = 0;
    tilemap.tile_at("three", 1, 0).id = 0;
    tilemap.tile_at("three", 1, 1).id = 0;
    tilemap.tile_at("three", 0, 1).id = 0;

    tilemap.display({
      filter: FilterType.nearest,
      scale: 3,
    });
  }

  override function config(config:luxe.AppConfig) {
    config.preload.textures.push({id:"assets/tiles.png"});
    return config;
  }

  override function onmousedown(event:MouseEvent){
    tilemap.tile_at_pos("two", event.pos, 3).id = 3;
  }
}

This example uses tiles.png:

Clicking on the tilemap changes the tiles id on layer 2, but the tile shows up above layer 3

PentaHelix commented 8 years ago

I'm pretty sure this issue is because at https://github.com/underscorediscovery/luxe/blob/master/luxe/tilemaps/Ortho.hx#L184 , each tile has the same depth, not a different depth depending on the layer it is in. My guess is that they are only sorted in the order in which they ware added /change, which changes when I change the tile id.

ruby0x1 commented 8 years ago

Sorry for the delay on replying here @PentaHelix , let us know if the fix helps your use

PentaHelix commented 8 years ago

Yeah that fixed it, thanks :)