This gist keeps a copy of my questions when using Amethyst. Hopefully it can help fill in some common questions beginners might have.
q. How can I create a sprite that always has a single image, for instance a background image.
a. (Partial) Can use UI texture. Ended up just creating a spritesheet with one image
q. Why would one use Entities<'s>
in a system, as opposed to just using the world? I have to specify storage for Entities<'s>
and it's so much more work!
a. using the world will lock that system to run all alone, no other system will be allowed to run while it runs
q. How can I get a single button press? In other libraries, this might be something like OnKeyDown
.
a. Use an EventChannel
in your system and match an InputEvent
q. Can I use an enum instead of a string for my bindings_config.ron
?'
a. Yes! Just specify the type. Here's an example:
let binding_path = my_assets_dir.join("bindings_config.ron");
let input_bundle =
InputBundle::<_, ActionKey>::new().with_bindings_from_file(binding_path)?;
^^^^^^^^^
Enum
q. How come Read
ing a component in a system still requires me to register the component manually, whereas ReadStorage
does not?
a. First of all, you don't read components, only resources. Component storages are resources as well, so ReadStorage is just a shortcut to Read<'a, ::Storage> Second, it doesn't. As long as your system does proper setup, the resource will be put in place using it's default impl.
q. wondering what best practice is here. So my prefab has 4 separate entities, but all entities share the same spritesheet. Looking at Evoli, it's defined like this - https://github.com/amethyst/evoli/blob/master/resources/prefabs/creatures/carnivore.ron#L11 however, since I have 4 separate entities, that method would load and create 4 separate texture handles to the same file, right?
a. there's a cache for the actual texture so that means you're only loading the image data once (within the same prefab file though, not sure about across multiple prefab files)
q. Do we have an example with nested prefabs? looks like prefabs only allow for the same PrefabData type in the entities array, but I'd like to parent several of the same PrefabData types to one differently typed master entity
a. we can't do that yet, @Jojolepro tried i believe, but you run into a recursion compilation error (want to compile prefab A, which contains prefab B, which contains A)