Skip to content

Painting individual pixels on dynamically generated sprites #8046

Answered by Aiden2207
pmorim asked this question in Q&A
Discussion options

You must be logged in to vote

You can create a texture from a dynamic Image. You'd probably want something like this:

pub fn setup_graphics(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
    const CHUNK_SIZE = 32;
    let mut pixels = Vec::with_capacity(CHUNK_SIZE * CHUNK_SIZE * 4);
    for y in 0..CHUNK_SIZE {
        for x in 0..CHUNK_SIZE {
              // Fancy algorithm
              // Push pixel to vec
              // Bear in mind, pixels are 4 bytes long, at least the way things are set up below
        }
    }

    let size = Extent3d {
        width: 32,
        height: 32,
        ..default()
    };
    let mut image = Image {
        data: pixels,
        texture_descriptor: TextureDescriptor 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pmorim
Comment options

Answer selected by pmorim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants