#Trying to create strong reference to TextureAtlas

11 messages · Page 1 of 1 (latest)

subtle ferry
#

Hi, so I'm doing this:

 let water_splash_texture_handle = asset_server.load("sprites/weapons/water_splash.png");
    water_splash_texture_handle.make_strong(&texture_atlases);
    let water_splash_texture_atlas = TextureAtlas::from_grid(
        water_splash_texture_handle,
        Vec2::new(265.0, 378.5),
        4,
        2,
        None,
        None
    );
    let water_splash_texture_atlas_handle = texture_atlases.add(water_splash_texture_atlas);

I need the atlas to be strong so I can spawn the texture later, but I'm not too sure how to go about it. With this code, in the from_grid function I'm getting an expected struct bevy::prelude::Image error. What's the proper way to do this?

#
let handle: Handle<TextureAtlas> = asset_server.get_handle("sprites/weapons/water_splash.png");
        let atlas = texture_atlases.get(&handle);```

My idea is to do something like this in another function, but obviously the atlas reference is gone by then
unkempt lichen
#
water_splash_texture_handle.make_strong(&texture_atlases);
#

is incorrect I think, if you just remove that line it should work?

#

water_splash_texture_handle is a handle to a texture, not a texture atlas, but you are passing it a reference to the TextureAtlas Assets not Image Assets

#

and asset_server.load returns a strong handle already

subtle ferry
unkempt lichen
#

When all the strong handles to an asset have been dropped, the asset is automatically deleted

#

You need to store the handle in a resource or component

#

To keep the asset alive

subtle ferry
#

I think I managed to work through this making the attack a resource, though the texture doesn't seem to be drawing