Showing icons on screen by script

Hello everyone! Is there a way to show an icon on screen by a short script and withouth the window frame?
Let's say I want to show icon 44 at x = 250 and y = 350.
How should I write if it was a script?
Hello everyone! Is there a way to show an icon on screen by a short script and withouth the window frame?
Let's say I want to show icon 44 at x = 250 and y = 350.
How should I write if it was a script?
pure script? with no plugins?

Something like this works but it's a bit odd to setup:
JavaScript:
const scene = SceneManager._scene;
scene._icon = new Sprite_StateIcon();
scene._icon.x = 250; scene._icon.y = 350;
$gameTemp._fakeBattler = new Game_Actor(1);
$gameTemp._fakeBattler._states = [4];
scene._icon.setup($gameTemp._fakeBattler)
scene.addChild(scene._icon);

That requires you to make a state and then pick that state that has the icon you want.
In the above example, it shows the icon from state #4 (poison in default MV)


Edit:
Ignore that ...that was really not a good way to do it lol
See below for a proper way. 🙂
Thank you for help. I think however that would be weird. I was trying to make huds with icons, where they change with 1/4, 2/4, 3/4, 4/4 of health of each character and I was going to show the state with an icon of an heart. Guess that's not the easiest way 🙁
Thank you for help. I think however that would be weird. I was trying to make huds with icons, where they change with 1/4, 2/4, 3/4, 4/4 of health of each character and I was going to show the state with an icon of an heart. Guess that's not the easiest way 🙁
Oh I'm dumb sometimes... I don't know why I didn't think of this before lol
Code:
let iconIndex = 84, pw = 32, ph = 32;
let sx = iconIndex % 16 * pw;
let sy = Math.floor(iconIndex / 16) * ph;
const scene = SceneManager._scene;
scene._icon = new Sprite(ImageManager.loadSystem('IconSet'));
scene._icon.setFrame(sx, sy, pw, ph);
scene._icon.x = 250; scene._icon.y = 350;
scene.addChild(scene._icon);
Yep that's the way to do it. 🙂

Multiple icons:
JavaScript:
let data = [{index:84, x:200, y:350},{index:84, x:250, y:350},{index:84, x:300, y:350},{index:84, x:350, y:350}]
const scene = SceneManager._scene; scene._icons = [];
data.forEach(v => {
let icon = new Sprite(ImageManager.loadSystem('IconSet'));
let iconIndex = v.index, pw = 32, ph = 32;
let sx = iconIndex % 16 * pw; let sy = Math.floor(iconIndex / 16) * ph;
icon.setFrame(sx, sy, pw, ph); icon.x = v.x; icon.y = v.y;
scene._icons.push(icon); scene.addChild(icon);
});
That will place 4 heart icons. 🙂

Looks like this:
Spoiler
1675464360088.png
Helpful?
Just asking. Wouldn't it be better to add it to Spriteset_Map instead of Scene_Map (or SceneManager._scene)?
Just asking. Wouldn't it be better to add it to Spriteset_Map instead of Scene_Map (or SceneManager._scene)?
Really depends on what is wanted to achieve.. joket never said it was specifically the map scene that the icons where going to be added to. Could even be battle, menu, etc.
looks like exactly what I needed! Yes they should appear only during map playing, with them disappearing in main menu, battle and other scenes. Is it possible to bind a different icon to a percentage of health of each character? Let's say actor 1 has 2/4 health = icon 1
actor 2 has 1/4 health = icon 2...and so on? Maybe a plugin would work better, to constantly check health of party
EDIT: Oh, wait! My bad. I missed that this was for MV. I would think what I did would work in MV, but I don't know for sure. Sorry for any confusion. And I also noticed that you specifically asked for scripting. So again, my bad.

I just made something for fun that I think is similar to what you are looking for. It doesn't require a plugin and it is just showing the concept of displaying icons based on HP and removing icons as the HP goes down. This uses a simple parallel event to test the concept.

I made a quick video of what it looks like if you are interested. I can also post screenshots of the event if this is something that you think might be helpful.

Again, no scripting involved so it is far less elegant.

I hope this helps!

Yup that's what it is needed (actually I'll make 1 heart per actor and upgrade the graphic depending on the health %) However I'd say a parallel event or a common event in parallel would reduce performance a lot in comparison of a plugin. Isn't it? Great job however!
Oh I'm dumb sometimes... I don't know why I didn't think of this before lol
Code:
let iconIndex = 84, pw = 32, ph = 32;
let sx = iconIndex % 16 * pw;
let sy = Math.floor(iconIndex / 16) * ph;
const scene = SceneManager._scene;
scene._icon = new Sprite(ImageManager.loadSystem('IconSet'));
scene._icon.setFrame(sx, sy, pw, ph);
scene._icon.x = 250; scene._icon.y = 350;
scene.addChild(scene._icon);
Yep that's the way to do it. 🙂

Multiple icons:
JavaScript:
let data = [{index:84, x:200, y:350},{index:84, x:250, y:350},{index:84, x:300, y:350},{index:84, x:350, y:350}]
const scene = SceneManager._scene; scene._icons = [];
data.forEach(v => {
let icon = new Sprite(ImageManager.loadSystem('IconSet'));
let iconIndex = v.index, pw = 32, ph = 32;
let sx = iconIndex % 16 * pw; let sy = Math.floor(iconIndex / 16) * ph;
icon.setFrame(sx, sy, pw, ph); icon.x = v.x; icon.y = v.y;
scene._icons.push(icon); scene.addChild(icon);
});
That will place 4 heart icons. 🙂

Looks like this:
Helpful?
What about changing the icon depending of a given actor health?

Actor ID 1: HP 100% --> icon 1;
Actor ID 1: HP 75% --> icon 2;
Actor ID 1: HP 50% --> icon 3;
Actor ID 1: HP 25% --> icon 4;
Actor ID 2: HP 100% --> icon 5;
Actor ID 2: HP 75% --> icon 6;

and so on? On a script with a refresh rate of 60 frames? (or more, to avoid performance crash?)

Original thread: https://forums.rpgmakerweb.com/threads/showing-icons-on-screen-by-script.154661/