Can't display a `TileMap`

(Eddy Cizeron) #1

Hello everyone

This is certainly a very silly newbie’s mistake but it’s been hours I’m desperately trying to make my tilemap appear:

let tiles = load_sprite_sheet(
	world,
	"texture/mini_tiles_spritesheet.png",
	"texture/mini_tiles_spritesheet.ron");

world.register::<TileMap<MyTile>>();

let mut transform = Transform::default();
transform.set_translation_xyz(AREA_WIDTH * 0.5, AREA_HEIGHT * 0.5, 0.0);

// Nowhere to be seen ...
let map = TileMap::<MyTile>::new(
	Vector3::new(70, 70, 1),
	Vector3::new(1, 3, 1),
	Some(tiles.clone())
);
world
	.create_entity()
	.with(map)
	.with(transform.clone())
	.build();

// ... whereas displaying a single tile works fine
let tile_render = SpriteRender {
	sprite_sheet: tiles.clone(),
	sprite_number: 0,
};
world
	.create_entity()
	.with(tile_render)
	.with(transform)
	.build();

My tile type being:

#[derive(Default, Clone)]
pub struct MyTile;
impl Tile for MyTile {
    fn sprite(&self, _: Point3<u32>, _: &World) -> Option<usize> { Some(0) }
}
impl Component for MyTile { type Storage = DenseVecStorage<Self>; }

I’m also specifying .with_plugin(RenderTiles2D::<MyTile, MortonEncoder>::default()) in the game builder section.

This seems to be mimicking what amethyst-master\examples\tiles\main.rs does, which actually works. Could it be related to my Cargo.toml ?

[dependencies]
specs = "0.16.1"
amethyst = "0.15.0"
amethyst_tiles = "0.3.0"

[features]
default = ["vulkan"]
empty = ["amethyst/empty"]
metal = ["amethyst/metal"]
vulkan = ["amethyst/vulkan"]

Thank you for any feedback

(Raymond) #2

I was able to replicate your issue. The default CoordinateEncoder for TileMap is MortonEncoder2D but your example is using MortonEncoder - with_plugin(RenderTiles2D::<MyTile, MortonEncoder>::default()) .

Try specifying:
let map = TileMap::<MyTile, MortonEncoder>

1 Like
(Eddy Cizeron) #3

@Raymond26 : that was it. Thanks.

(Gravit22) #4

It is very nooby question but how you can “use” TileMap?