Add a rendering system using temporary images #61

Merged
CoCo_Sol merged 26 commits from renderer into main 2024-03-05 18:08:56 +00:00
Showing only changes of commit 29ba228716 - Show all commits

View file

@ -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)]
struct TilesOffset(Vec2);
struct TilesGap(Vec2);
/// The size of the tiles in the map.
#[derive(Resource, Clone, Copy)]
@ -54,7 +54,7 @@ impl Tile {
/// Init resources related to the rendering of the map.
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. }))
}
@ -63,13 +63,13 @@ fn render_map(
query: Query<(Entity, &TilePosition, &Tile), Changed<Tile>>,
mut commands: Commands,
asset_server: Res<AssetServer>,
tiles_offset: Res<TilesOffset>,
tiles_gap: Res<TilesGap>,
tiles_size: Res<TilesSize>,
) {
for (entity, position, tile) in query.iter() {
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(
translation_2d.x,
translation_2d.y,