Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Improve "Simple tilemap example" #167

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,32 @@ use bevy_tilemap::prelude::*;
use bevy::asset::HandleId;
use bevy::prelude::*;

// This must be set in Asset<TextureAtlas>.
let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>());

let mut tilemap = Tilemap::new(texture_atlas_handle, 32, 32);
// Build a default Tilemap with 32x32 pixel tiles.
let mut tilemap = Tilemap::default();

// Coordinate point with Z order.
let point = (16, 16, 0);
let tile_index = 0;
tilemap.set_tile(point, tile_index);
// We need a Asset<TextureAtlas>. For this example we get a random one as a placeholder.
let texture_atlas_handle = Handle::weak(HandleId::random::<TextureAtlas>());

tilemap.spawn_chunk_containing_point(point);
// Set the texture atlas for the Tilemap
tilemap.set_default_texture_atlas(texture_atlas_handle);

// Create tile data
let tile = Tile {
// 2D location x,y (units are in tiles)
point: (16,16),

// Which tile from the TextureAtlas
sprite_index = 0,

// Which z-layer in the Tilemap (0-up)
sprite_order = 0,

// Give the tile an optional green tint
tint: bevy::render::color::Color::GREEN,
};

// Insert a single tile
tilemap.insert_tile( tile);
```

Of course, using the `Tilemap::builder()` this can be constructed with many more
Expand Down