How to Change an Entity's Sprite

Started by lefthandedhero, October 28, 2023, 03:11:41 AM

Previous topic - Next topic
October 28, 2023, 03:11:41 AM Last Edit: November 03, 2023, 03:25:29 PM by lefthandedhero
I am trying to create a custom state for the hero that represents the hero being in a different form (think something like Wolf Link from Twilight Princess): while the hero is in this custom state, the hero uses a different sprite and a different main attack. I was wondering how to change the hero's sprite.


EDIT: I now realize that I probably phrased this question poorly. I was wondering, for any entity, how to program it to use a specific sprite under certain conditions. I watched the video on sprite and animation files, so I know how to create a sprite. But, once I have created a sprite, how do I tell the engine, "under this specific condition, this entity's sprite is now (a specific sprite)"?

I want to know this so I can change the hero's appearance during the game, but I really want to know how to do this with any entity. For instance, I currently have a custom entity that currently only exists to always follow the hero, and I want their appearance to change whenever the hero's appearance changes.


EDIT2: I think I may have found a solution: using entity:remove_sprite() then entity:create_sprite(), I have tested it, and it seems to work.

October 28, 2023, 10:00:46 PM #1 Last Edit: October 28, 2023, 10:08:34 PM by PeterB
Hi,

Tunic level relates to the Hero's defense level.

For example in Zelda Tunic level 1 is green, level 2 is blue and level 3 is red.

You therefore need to have a different colour sprite for each tunic level for every hero sprite.

That way when you upgrade your tunic in your game you can automatically change all your hero sprites to the next colour.

If you have a look in the sample quest that comes with the Quest Editor, in the sprites/hero folder you can see the three tunic sprite sets. It is the items/tunic script then then calls the relevant variant and updates the hero's sprite colour.

If you want to set up a different sprite then you just need to add a new animation to tunic1, tunic2 and tunic3 and call that animation from a script, at least i think that is the easiest way to do it.

Quote from: PeterB on October 28, 2023, 10:00:46 PM
Hi,

Tunic level relates to the Hero's defense level.

For example in Zelda Tunic level 1 is green, level 2 is blue and level 3 is red.

You therefore need to have a different colour sprite for each tunic level for every hero sprite.

That way when you upgrade your tunic in your game you can automatically change all your hero sprites to the next colour.

If you have a look in the sample quest that comes with the Quest Editor, in the sprites/hero folder you can see the three tunic sprite sets. It is the items/tunic script then then calls the relevant variant and updates the hero's sprite colour.

Thank you; that makes a lot of sense. There probably will not be tunic upgrades in the game I am making, so I guess I can ignore the stuff about tunic level.

Quote from: PeterB on October 28, 2023, 10:00:46 PM
If you want to set up a different sprite then you just need to add a new animation to tunic1, tunic2 and tunic3 and call that animation from a script, at least i think that is the easiest way to do it.

I see. I should point out that I'm very new to Solarus and I'm still learning how sprites and animations work.

Would adding an animation be sufficient? I want to essentially create another appearance that the hero uses when in a custom state.

Yes it would, as long as you replicate it in all the tunic variants. It can then be called with hero:set_animation(animation, [callback]) from the relevant game, item, map script etc depending on what or where the new animation was called or initiated.

If it is a permanent change then using the hero metatable may be the best way to do it :)