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

Tilemap, changing the depth of all tiles in a layer make some tiles disappear #364

Closed Blist closed 8 years ago

Blist commented 8 years ago

Hi,

I have a map with multiple layer. I want to make the depth of a layer behind my player, but I have a bug that occurs randomly. When I want to change the depth of a whole layer some tiles disappear.

Important thing: I don't have this bug on cpp build just with web build.

my code to update the depth

public function uplayer(name:String, depth:Float) {
        var layer:luxe.tilemaps.TilemapVisualLayerGeometry = tilemap.visual.geometry_for_layer(name);
        for (row in layer) {
            for (tile in row) {
                if (tile != null) {
                    tile.depth = depth;
                }
            }
        }
    }

A snippet to reproduce the bug :

import luxe.Input;
import phoenix.Texture;
import luxe.tilemaps.Tilemap;

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

    override function ready() {
        tilemap = new Tilemap({
            x: 0,
            y: 0,
            w: 16,
            h: 16,
            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_tiles_fill_by_id("one",1);

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

        uplayer("one", 3);

    }

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

    public function uplayer(name:String, depth:Float) {
        var layer:luxe.tilemaps.TilemapVisualLayerGeometry = tilemap.visual.geometry_for_layer(name);
        for (row in layer) {
            for (tile in row) {
                if (tile != null) {
                    tile.depth = depth;
                }
            }
        }
    }
}

the tile is use for the snippet (from PentaHelix's issue)

tiles.png

Blist commented 8 years ago

Some strange thing,

if I trace the transform.pos of each geometry that I have update, holes disappear ...

Without trace : without With trace : with

Snippet

public function uplayer(name:String, depth:Float) {
        var layer:luxe.tilemaps.TilemapVisualLayerGeometry = tilemap.visual.geometry_for_layer(name);
        for (row in layer) {
            for (tile in row) {
                if (tile != null) {
                    tile.depth = depth;
                    trace(tile.transform.pos);
                }
            }
        }
    }

Maybe, tilemap refresh his display before that all tiles are updates ?

KeyMaster- commented 8 years ago

Fixed with 5c38950 and 596c821. Geometry sorting was getting confused due to some subtle bugs.