How to darken or dim a sprite?

You can apply tints and flashes to a sprite without much trouble, but I'm not sure how to make it black out or darken. What code would I need to make a sprite show up as darker or dimmed?
Code:
sprt.setColorTone([red, green, blue, gray]);

All values go between -255 and 255 iirc.
That is exactly what I was looking for, thank you!
You can apply tints and flashes to a sprite without much trouble, but I'm not sure how to make it black out or darken. What code would I need to make a sprite show up as darker or dimmed?
how exactly do you get these codes to work, can you use them in moveroutes? ive been trying
@bazrat Either directly in the game's code or script call, but you need to be able to call the sprite in the script command.
@bazrat Either directly in the game's code or script call, but you need to be able to call the sprite in the script command.
so $gamePlayer.setColorTone([255, 0, 0, 0]); ? im trying this in game with no luck. im sorry im not familiar with calling a sprite 🙁
@bazrat $gamePlayer derives from the Game_Player object. It's a game object and not a sprite. A sprite is an entity added to a scene, so it isn't a global object like anything that starts with $game. To access a sprite, you need to find it inside the scene.
The default code (cf rpg_sprites.js, Spriteset_Map.prototype.createCharacters) stores all the sprites as members of the spriteset: events, vehicles, followers, player (in that order). So, assuming you have no other plugins that specifically change that pattern, the player sprite is the last in the list and you can reference/tint it like this:
Code:
var tmp = SceneManager._scene._spriteset._characterSprites;
var playerSprite = tmp[tmp.length - 1];
playerSprite.setColorTone([-128, -128, -128, 0]);  // darken
The default code (cf rpg_sprites.js, Spriteset_Map.prototype.createCharacters) stores all the sprites as members of the spriteset: events, vehicles, followers, player (in that order). So, assuming you have no other plugins that specifically change that pattern, the player sprite is the last in the list and you can reference/tint it like this:
Code:
var tmp = SceneManager._scene._spriteset._characterSprites;
var playerSprite = tmp[tmp.length - 1];
playerSprite.setColorTone([-128, -128, -128, 0]);  // darken
honestly, you are amazing. thank you
May I ask, if I like to do the same thing but on event sprites, how should I script call?
May I ask, if I like to do the same thing but on event sprites, how should I script call?
The default code (cf rpg_sprites.js, Spriteset_Map.prototype.createCharacters) stores all the sprites as members of the spriteset: events, vehicles, followers, player (in that order).
So you would get the character sprite at index eventId - 1 (-1 because arrays start at index 0, but event IDs start at 1). E.g. for a specific ID:
JavaScript:
var tmp = SceneManager._scene._spriteset._characterSprites;
var eventId = 12;  // target event ID 12
var eventSprite = tmp[eventId - 1];
eventSprite.setColorTone([-128, -128, -128, 0]);  // darken
...or, for "This Event":
JavaScript:
var eventId = this.eventId();
(As I noted back in 2019, some plugins may make this fail to work as intended.)

  • For vehicles you could follow the event example, with an offset of $gameMap.events().length, e.g.
    JavaScript:
    var tmp = SceneManager._scene._spriteset._characterSprites;
    var di = $gameMap.events().length;
    var vehicleSprite = tmp[di + 0];  // +0 (boat), +1 (ship), +2 (airship)
    vehicleSprite.setColorTone([-128, -128, -128, 0]);  // darken

  • For followers you could just use the player example, except with -2 for the first follower, -3 for the second, etc. E.g.
    JavaScript:
    var tmp = SceneManager._scene._spriteset._characterSprites;
    var followerSprite = tmp[tmp.length - 2];  // first follower
    followerSprite.setColorTone([-128, -128, -128, 0]);  // darken

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

👋

Original thread: https://forums.rpgmakerweb.com/threads/how-to-darken-or-dim-a-sprite.107164/