#Call nearest or linear on Image inside Handle<Image> before adding it to TextureAtlas?

26 messages · Page 1 of 1 (latest)

tranquil raft
#

During my setup I'm loading several spritesheets and I'm getting back Handle<Image> types.
Like this:
let texture_handle_buildings: Handle<Image> = asset_server.load("spritesheet/buildings.png");

I then create TextureAtlas's of these and add them to ResMut<Assets<TextureAtlas>>
My question is how do I call drill into Handle<Image> and then call .nearest() or .linear() on the images before adding them to the TextureAtlas?

surreal fractal
#

You can now specify this in the loader settings when loading your image rs let texture_handle_buildings: Handle<Image> = asset_server.load_with_settings("spritesheet/buildings.png", |settings: &mut ImageLoaderSettings| { settings.sampler = ImageSampler::nearest(); });

tranquil raft
#

@surreal fractal this worked very well thank you!
Although I still don't know how to access the Image inside a Handle (not sure if this is intended) I don't need to anymore with the load_with_settings idea.

surreal fractal
#

You can get images from handles (once they're loaded) by requesting them from an Assets resource: rs /// Pretend this handle comes from somewhere that makes sense fn foo(images: ResMut<Assets<Image>>, handle: Handle<Image>) { let img = images.get_mut(handle).unwrap(); }

tranquil raft
#

something interesting.. while mixing sprites of linear and nearest.. seems the spritesheet tiles bleed into one another. The spritesheet tile to left of this is white.. so you can see a sliver of it.. and i noticed it's like that for all the ones using linear.

#

this is with the tilesheet using "nearest"

surreal fractal
#

This is common with linear filtering, traditionally spritesheets designed to be used this way include padding around sprites to avoid this

tranquil raft
#

if im doing 32x32 sprites.
I could do a Vec2::new(1.0, 1.0) padding and then make my sprites 34x34 in actuality and leave a 1 pixel spacing around it?

#

or would that make 33x33?

surreal fractal
#

That's a 34x34

tranquil raft
#

kk.. let me give it a whirl

surreal fractal
#

Or was it 2x2? To indicate 2 pixels of padding between each sprite (1 pixel of padding for each)

#

Well, I suppose it could be either, depending on how you author the texture - 33x33 or 34x34, 1x1 or 2x2 padding - depending if you use 1 pixel of padding between sprites or 1 pixel of padding around each

tranquil raft
#

im trying with 32x32 with 1.0, 1.0 of padding .. and my sprite sheet is 34x34

#

^ this made everything looks terrible

#

maybe i need an offset too..

#

since im starting now with padding .. need to offset 1.0, 1.0

#

?

surreal fractal
#

Right... so is it 1x1 of padding around each sprite, or between sprites?

tranquil raft
#

im trying with 32x32 with 2.0, 2.0 of padding, 1.0, 1.0 offset now..

surreal fractal
#

The padding in from_grid refers to how many pixels are between sprites, the offset refers to how many pixels from the top-left (since bottom-right padding would be completely ignored)
So if you created a 1x1 padding around each sprite and put them together, it would be a 1x1 offset and 2x2 padding

tranquil raft
#

nice fixed

#

appreciate the help

surreal fractal
#

Nice - now one thing you can do is make the padding to be the same color as the edge of each sprite. This should eliminate that border looking faded