generated from tipragot/rust
Add a rendering system using temporary images #61
|
@ -18,9 +18,9 @@ impl Plugin for RendererPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The offset between the center of the tiles in the map.
|
/// The gap between the center of the tiles in the map.
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct TilesOffset(Vec2);
|
struct TilesGap(Vec2);
|
||||||
|
|
||||||
/// The size of the tiles in the map.
|
/// The size of the tiles in the map.
|
||||||
#[derive(Resource, Clone, Copy)]
|
#[derive(Resource, Clone, Copy)]
|
||||||
|
@ -54,7 +54,7 @@ impl Tile {
|
||||||
|
|
||||||
/// Init resources related to the rendering of the map.
|
/// Init resources related to the rendering of the map.
|
||||||
fn init_resources_for_rendering(mut commands: Commands) {
|
fn init_resources_for_rendering(mut commands: Commands) {
|
||||||
commands.insert_resource(TilesOffset(Vec2 { x: 70., y: 40. }));
|
commands.insert_resource(TilesGap(Vec2 { x: 70., y: 40. }));
|
||||||
commands.insert_resource(TilesSize(Vec2 { x: 125., y: 100. }))
|
commands.insert_resource(TilesSize(Vec2 { x: 125., y: 100. }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,13 +63,13 @@ fn render_map(
|
||||||
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
|
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
tiles_offset: Res<TilesOffset>,
|
tiles_gap: Res<TilesGap>,
|
||||||
tiles_size: Res<TilesSize>,
|
tiles_size: Res<TilesSize>,
|
||||||
) {
|
) {
|
||||||
for (entity, position, tile) in query.iter() {
|
for (entity, position, tile) in query.iter() {
|
||||||
let texture = tile.get_texture(&asset_server);
|
let texture = tile.get_texture(&asset_server);
|
||||||
|
|
||||||
let translation_2d = tiles_offset.0 * position.to_pixel_coordinates();
|
let translation_2d = tiles_gap.0 * position.to_pixel_coordinates();
|
||||||
let translation = Vec3::new(
|
let translation = Vec3::new(
|
||||||
translation_2d.x,
|
translation_2d.x,
|
||||||
translation_2d.y,
|
translation_2d.y,
|
||||||
|
|
Loading…
Reference in a new issue