#Trying to render an image without the AssetServer

12 messages · Page 1 of 1 (latest)

crystal flicker
#

Here is the part of the code that spawns the sprites:

let image = image::load_from_memory(include_bytes!("../assets/tile_image.png")).unwrap();

let (image_width, image_height) = image.dimensions();
assert!(image_width >= 3 && image_height >= 3);

let tile_size = Vec2::new(
    WINDOW_RESOULUTION.x / X_TILES as f32,
    WINDOW_RESOULUTION.y / Y_TILES as f32,
);

for (x, y) in (0..X_TILES).flat_map(|x| (0..Y_TILES).map(move |y| (x, y))) {
    let tile_start = Vec2::new(
        WINDOW_RESOULUTION.x * x as f32 / X_TILES as f32,
        WINDOW_RESOULUTION.y * y as f32 / Y_TILES as f32,
    );

    let dynamic_tile_image = image.crop_imm(tile_start.x as u32, tile_start.y as u32, tile_size.x as u32, tile_size.y as u32);
    let tile_image = asset_server.add(Image::from_dynamic(dynamic_tile_image, false, RenderAssetUsages::default()));
    commands.spawn((
        Sprite {
            image: tile_image,
            custom_size: Some(WINDOW_RESOULUTION),
            ..default()
        },
        Transform::from_translation(tile_start.extend(0.0)),
    ));
}
karmic osprey
#

"Dimension Y is zero"

crystal flicker
karmic osprey
#

What

#

Y is 0

crystal flicker
karmic osprey
#

I didn't either

#

Just debug whatever is the y dimension

#

So the height of the image

crystal flicker
crystal flicker
#

Im confused why do I need to debug this?