Table of Contents
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
original source: Lunos' Pokecommunity post
Well, there isn't much to say.
Normally, object events are not loaded until they're just about to be visible on the screen.
Something like this can be troublesome in very specific cases.
One such case is if you want to write a cutscene where the camera slowly moves to a certain object event that is standing near water.
The reflection won't be loaded until the object event is about to get on screen, and will thus look as if it popped out of nowhere, instead of being there all along.
So what did I do to deal with this very specific thing?
I added a flag that while set, forcefully makes the game load the objects that are outside of the screen.
The usage I gave to it is simple. I set it before being warped into a map in order to start an event, and then I cleared it before the end of said event.
To implement this, we'll go to the src/event_object_movement.c file. Specifically, to the UpdateObjectEventOffscreen function.
As we can see, this function updates the status of an object event to signal whether it's outside of the screen or not.
To keep our object events loaded, we just need to add a check however we want, that sets the offScreen value of the object event according to our needs.
In my case, I decided to define a flag. When it's set, every NPC will be considered to be within the game's screen, so we'll add a new if statement.
include/constants.flags.h
rename an unused flag (eg, #define FLAG_UNUSED_0x04F 0x4F // Unused Flag
#define FLAG_FORCE_LOAD_OFFSCREEN_OBJECT 0x4F
src/event_object_movement.c
in section
static void UpdateObjectEventOffscreen(struct ObjectEvent *objectEvent, struct Sprite *sprite)
add the below after these two if lines:
if ((s16)x >= DISPLAY_WIDTH + 16 || (s16)x2 < -16)
objectEvent->offScreen = TRUE;if ((s16)y >= DISPLAY_HEIGHT + 16 || (s16)y2 < -16)
objectEvent->offScreen = TRUE;
if (FlagGet(FLAG_FORCE_LOAD_OFFSCREEN_OBJECT))
objectEvent->offScreen = FALSE;
so the section should now be
static void UpdateObjectEventOffscreen(struct ObjectEvent *objectEvent, struct Sprite *sprite)
{
u16 x, y;
u16 x2, y2;
const struct ObjectEventGraphicsInfo *graphicsInfo;
objectEvent->offScreen = FALSE;
graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId);
if (sprite->coordOffsetEnabled)
{
x = sprite->x + sprite->x2 + sprite->centerToCornerVecX + gSpriteCoordOffsetX;
y = sprite->y + sprite->y2 + sprite->centerToCornerVecY + gSpriteCoordOffsetY;
}
else
{
x = sprite->x + sprite->x2 + sprite->centerToCornerVecX;
y = sprite->y + sprite->y2 + sprite->centerToCornerVecY;
}
x2 = graphicsInfo->width;
x2 += x;
y2 = y;
y2 += graphicsInfo->height;
if ((s16)x >= DISPLAY_WIDTH + 16 || (s16)x2 < -16)
objectEvent->offScreen = TRUE;
if ((s16)y >= DISPLAY_HEIGHT + 16 || (s16)y2 < -16)
objectEvent->offScreen = TRUE;
if (FlagGet(FLAG_FORCE_LOAD_OFFSCREEN_OBJECT))
objectEvent->offScreen = FALSE;
}
And that's pretty much it.