Replies: 1 comment
-
After searching in the code for the #[test]
fn test_spawn_texture_atlas() {
let mut app = App::new();
app.add_plugins(AssetPlugin::default());
app.init_asset::<Image>();
app.init_asset::<TextureAtlas>();
IoTaskPool::get_or_init(|| TaskPool::new());
let asset_server = app.world.get_resource::<AssetServer>().unwrap();
let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
let texture_atlas =
TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, None, None);
let mut texture_atlases = app.world.get_resource_mut::<Assets<TextureAtlas>>().unwrap();
let texture_atlas_handle = texture_atlases.add(texture_atlas);
app.world.spawn(
SpriteSheetBundle {
texture_atlas: texture_atlas_handle,
sprite: TextureAtlasSprite::new(0),
transform: Transform::from_scale(Vec3::splat(6.0)),
..default()
},
);
app.update();
} Now it works without any panic. However, maybe someone has a better idea to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I want to test a system in bevy 0.12.1, which uses texture atlases. As a minimal example just image a test case like that:
Unfortunately, when I run the test, I just get a panic telling me, that the
Assets<Shader>
resource is missing:So, now I was trying to add more plugins from
DefaultPlugin
in order to get the resource. But every time, when I add a new plugin, it complains about something different missing. In the end, if I take all plugins fromDefaultPlugin
it is panicing, because I do stuff outside of the main event loop.I tried various combinations of plugins and I'm really lost: How can I satisfy the minimal requirements for testing systems, like in my example?
Beta Was this translation helpful? Give feedback.
All reactions