-
Notifications
You must be signed in to change notification settings - Fork 0
Loading Custom Sprites & Custom Audio
To replace the sprites for your bro's Main Sprite, Gun Sprite, Special Icon Sprite, Avatar Sprite, or Cutscene Sprite, use the parameters section in your JSON file (see Parameters). These parameters handle sprite loading automatically:
-
Sprite
- Main character sprite -
GunSprite
- Gun sprite -
SpecialIcons
- Special icon sprite sheet -
Avatar
- Avatar sprite
For loading additional sprites programmatically (e.g., for custom projectiles or dynamically changing sprites during abilities), you can use BroMakerLib's ResourcesController.
In order to do this, I would recommend you use BroMakerLib's ResourcesController.cs
The ResourcesController class, which is builtin to BroMakerLib, has several useful methods for loading sprites and AudioClips.
The main methods I would recommend that you use for loading custom sprites are
public static Material GetMaterial(string filePath);
public static Material GetMaterial(string path, string fileName);
These methods will use the default shader that most Broforce objects use, and they will also store the material in a cache so that they don't have to reload it from the file every time your bro is respawned. So if you use these methods, you don't have to worry about adding in your own caching system, you can just call them and have the results automatically cached.
The main methods I would recommend that you use for loading AudioClips are
public static AudioClip GetAudioClip(string filePath);
public static AudioClip GetAudioClip(string path, string fileName);
These methods also cache the results similar to the previous ones.
If you need to create a sprite which has transparent pixels, you should make sure to change the layer of the GameObject to which your sprite is attached to a layer that supports transparency. I've found that layers 5, 19, and 28 work. Layers 5 and 28 make the object appear in front of certain objects like grass and the railings on bridges, which objects normally don't appear in front of. Layer 19 makes the object appear behind these objects, so it's probably the most useful.
In order to change the sprite of a Broforce Object you'll generally need to change the material of the MeshRenderer. This should look something like this:
base.GetComponent<Renderer>().material = nameOfYourCustomMaterialVariable;
I would avoid changing the sharedMaterial variable, because this can often affect other unrelated objects.
If you have questions or need help with creating custom bros, you can join the Free Lives Discord Server and post your questions in the bf-mods channel.