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 Posts

Latest Profile Posts

I FINALLY DID IT! 5 years making my very first game and I just officially released it on STEAM..... OMG..... I can say I finished a game! The feelings!!!!!
Stream will be live shortly! I am going to be playing some Among Us! Feel free to drop by!
Ami
tv program always get the ratings (it's the reason why drama series has 1000+ episode),also full and nonsense of censorship (weird blur, a scene getting cut because the unconvenient viewer,but it unconvenient to me either. you never see what the original is)

i know the reason is to take cover the viewer from the negative thing,but i just laughing and mocking of them that they're always suck :guffaw:
Star Chart Idea - Just something I am working on.
My sister learned spanish the old fashioned way and saw my way of conjugating. I don't use the formal method and just wing it. I thought her heart might explode. Apparently, different words use different endings. Weird part is even though I never learned the difference, I still can tell when the endings "look wrong".

Forum statistics

Threads
104,456
Messages
1,006,413
Members
135,964
Latest member
Musixim
Top