How do I randomize an NPC object sprite color palettes onDraw while rotating? (solved)
Posted: Sun Aug 07, 2022 10:16 am
Currently, I have the horizontal sprite sheet of an NPC object (1 frame) with the others being the same but different color palettes next to the original one. In my custom NPC Lua file, I can't seem to have it randomize the starting color and rotate simultaneously.
I have tried once or twice just randomizing the color (without the rotation) in the onDraw function. I used a random value to determine where the image should source from (in terms of pixels). However, either the NPCs were stuck with one color at a time or the NPC is flashing like a Disco shell.
I did get the rotation to work (thanks to SetaYoshi's wormhole) in terms of creating a sprite. The problem is that I can't try the same with the color randomization. When I override the sprite sheet, it stretches to the object's size (32x32) instead of sourcing the sprite from a particular position. Besides that, I am unable to come up with where I should put my randomizer in (especially the sourceX part), as well as some other details between the sprite initialization and the onDraw function. Putting the parts in either places don't do anything.
Here is the NPC Lua code in question:
And the lines/parts I probably needed to add:
Many thanks to someone who can help. And I am definitely keeping this useful stuff for future uses.
I have tried once or twice just randomizing the color (without the rotation) in the onDraw function. I used a random value to determine where the image should source from (in terms of pixels). However, either the NPCs were stuck with one color at a time or the NPC is flashing like a Disco shell.
I did get the rotation to work (thanks to SetaYoshi's wormhole) in terms of creating a sprite. The problem is that I can't try the same with the color randomization. When I override the sprite sheet, it stretches to the object's size (32x32) instead of sourcing the sprite from a particular position. Besides that, I am unable to come up with where I should put my randomizer in (especially the sourceX part), as well as some other details between the sprite initialization and the onDraw function. Putting the parts in either places don't do anything.
Here is the NPC Lua code in question:
Spoiler: show
Spoiler: show
Many thanks to someone who can help. And I am definitely keeping this useful stuff for future uses.