RMMV Access an event's Sprite object

Ellie Jane

Veteran
Veteran
Joined
Mar 17, 2012
Messages
752
Reaction score
1,488
First Language
English (UK)
Primarily Uses
RMMV
Morning guys,

So I have created a function in the Sprite class. Just imagine it's something like this:

Code:
Sprite.prototype.helloWorld = function(msg) {
  console.log(msg);
};
I need to call this function for the Sprite that draws a particular event, let's say event 214 on the map.

I thought it would be as simple as: $gameMap.event(214).sprite.helloWorld("hi");

But there doesn't seem to be a property "sprite" of event. In fact trawling through the MV scripting reference, I cannot even find a Sprite attached to an Event (or Character, or CharacterBase).

Having created the function I want, how do I call it for a given event's Sprite object?
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,446
First Language
English
Primarily Uses
N/A
You don't want to do it on Sprite. Do it on
Game_Character.prototype, or Game_Event.prototype
Sprite is a class more based around showing and tracking the sprite itself, it goes in the spriteset of Scene_Map.
The objects that get returned from the $gameMap.events calls aren't Sprite objects

EDIT:
Since the title of the thread is accessing an event's sprite object, I'll go a step further, and explain how to actually do that from the getting the event.
There are several ways, here's the way I do it. I have a function for it, so I'll just share that.
JavaScript:
function findInSpriteset(char){ //char is the event object ex: $gameMap.event(214)
    let spset = SceneManager._scene._spriteset._characterSprites;
    let i = {};
  
    for(i of spset){
        if(i._character == char)
        return i; 
    }
    return false;
}
The object that gets returned would actually be a Sprite_Character, which gets a prototype from the Sprite_Base, which gets a prototype from Sprite. So the function you wrote in your post would be accessible on the object that gets returned here
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Halloween, a day where kids are encouraged to take candy from strangers.
Stream will be live shortly with a session of the Interactive Text Adventure! Feel free to drop by!
Took a break from spriting dinosaurs to carve a dinosaur pumpkin.

Little early but to all of you that celebrate it :

Tomorrow is Halloween! I can't wait to go to Boxi Park and show off my costume! Also one of Dad's friends is staying the night, so he might get to see the show.

Forum statistics

Threads
104,669
Messages
1,007,972
Members
136,157
Latest member
Tian
Top