Skip to content

Adding a New Trainer Front Picture

Tyler Scarff edited this page Jul 23, 2022 · 1 revision

Adding the Trainer Pic constant

Open /include/constants/trainers.h and search for "TRAINER_PIC". You should find a list of TRAINER_PIC constants. Add your new constant to the end and set the value to the next highest number.

In my case, the trainer pic definition looks like this: #define TRAINER_PIC_LEADER_MAX 94

In src/data/trainer_graphics/front_pic_tables.h, add an entry to the gTrainerFrontPicTable struct. For me, the entry looks like this: [TRAINER_PIC_LEADER_MAX] = {.size = 8, .y_offset = 1},

Some definitions

Start by setting up the animations for the trainer. All trainers have one frame of animation, so this isn't too difficult. Open src/data/trainer_graphics/front_pic_anims.h

The file starts with a list of AnimCmd. Add a new one that follows the same pattern as the others. In my case, it looks like this:

static const union AnimCmd *const sAnims_LeaderMax[] ={
    sAnim_GeneralFrame0,
};

Now, to use that animation. Add an entry to gTrainerFrontAnimsPtrTable[] associating your trainer pic constant to the new animation. It should look like this:

const union AnimCmd *const *const gTrainerFrontAnimsPtrTable[] =
{
[TRAINER_PIC_HIKER] = sAnims_Hiker,
...
[TRAINER_PIC_LEADER_MAX] = sAnims_LeaderMax,
}

Next, we can add the front pic to the game's sprite sheet. Back in src/data/trainer_graphics/front_pic_tables.h, navigate to the gTrainerFrontPicTable[] struct. Inside of this struct, add an entry pointing your TRAINER_PIC to the trainer graphic you created before. For this step and the next, the first argument should be the text following "TRAINER_PIC_" in your original constant. The second argument will be the location of the image file. This should look something like:

TRAINER_SPRITE(LEADER_MAX, gTrainerFrontPic_LeaderMax, 0x800),

If using a custom palette, you will also need to assign the palette. Navigate to the gTrainerFrontPicPaletteTable[] struct and add an entry for your trainer and palette. The second argument will be defined in a later step and will contain the location of the palette file. It should look like: TRAINER_PAL(LEADER_MAX, gTrainerPalette_LeaderMax)

Creating the image and telling the game where to find it!

First, you'll need to create your trainer image! I recommend using GraphicsGale for this. The trainer image will need to be 4bit (16 color) and 64 x 64 pixels. Then, save the image as a .png in graphics/trainers/front_pics and the palette as a .pal in graphics/trainers/palettes. (You can use different file locations if you want, but this is where all other trainer front pics are saved)

Next, open src/data/graphics/trainers.h. Add two lines to include your new image and palette. The string will need to match the file location of your image and palette. For example:

const u32 gTrainerFrontPic_LeaderMax[] = INCBIN_U32("graphics/trainers/front_pics/leader_max_front_pic.4bpp.lz");
const u32 gTrainerPalette_LeaderMax[] = INCBIN_U32("graphics/trainers/palettes/leader_max.gbapal.lz");

NOTE You'll notice that the file types here are not .png and .pal. The .4bpp and .gbapal files are created automatically as part of the build.

Open include/graphics.h and navigate to the list of gTrainerFrontPic_... constants. (The section begins with the comment "trainer sprites") Add a declaration for a new constant for your trainer pic:

extern const u32 gTrainerFrontPic_LeaderMax[];

In the section just below this, add the TrainerPalette declaration

extern const u32 gTrainerPalette_LeaderMax[];

Adding the image to a trainer!

The final step is here! Open src/data/trainers.h and look for the trainer who needs a new image. Take the line that starts with ".trainerPic = " and replace it with the constant you defined in the first step. For my trainer:

[TRAINER_MAX] =
    {
        ...
        .trainerPic = TRAINER_PIC_LEADER_MAX,
        ...
    },

Now build the ROM, fight the trainer, and admire the new Trainer Picture!

Troubleshooting

If you get an error that looks like this:

Failed to open "graphics/trainers/front_pics/leader_max_front_pic.png" for reading. Failed to open JASC-PAL file "graphics/trainers/palettes/leader_max.pal" for reading. make: *** [Makefile:275: graphics/trainers/front_pics/leader_max_front_pic.4bpp] Error 1 make: *** Waiting for unfinished jobs.... make: *** [Makefile:277: graphics/trainers/palettes/leader_max.gbapal] Error 1

You may need to "touch" the image and palette files using the command line. This is most likely to occur on Windows using WSL. Here is an example:

touch graphics/trainers/palettes/leader_max.pal graphics/trainers/front_pics/leader_max_front_pic.png 
Clone this wiki locally