RMMV Access an event's Sprite object

Ellie Jane

Veteran
Veteran
Joined
Mar 17, 2012
Messages
752
Reaction score
1,487
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 Posts

Latest Profile Posts

Its been almost 6 months since i've been here last and 5 years before that. the worst part is losing the game you were working on in a cpu fire.

Well time to go at it again.
my game is coming together im so happy
In this day and age, i might switch back to RMXP. I’ve lost faith in all the new plugins.
Wow it's been forever since I last logged in! I STILL want to make a game... I'll start it one day for sure!! It's a dream of mine.
This days I couldn't do anything... My mind is so confused and I couldn't work at all, I only wanted to play video games with my friends and that made all my projects delay a lot. Someone else feels this kind of thing sometimes? :/

Forum statistics

Threads
104,286
Messages
1,005,259
Members
135,796
Latest member
PurplexiaSphinx
Top