I am new to Defold, and I was wondering if anyone had any advice how to structure a character “dress up” style game.
I have a few hundred images for the clothing/accessories, etc… and I would hope that I don’t have to manually add them all and place them in the .gui editor viewport…
I’m not looking for drag & drop style, but a table/grid of items per category that when clicked, would swap out the current piece on the character.
Could someone give me a little direction so I can be moving in the right direction here?
I have worked through all the tutorial projects that come with Defold 2
I have read through most of the documentation pages as well, so I have an idea of how the system works.
Would having an instance of each item off-screen and then changing the x/y coordinates when the grid button gets clicked be the best way to do it?
Are there images vastly different? If the clothing is similar enough you can always use gui.set_animation() to change between the images in an atlas. If you then store the different images that can go into the same slot in a lua table like this clothes = {"trousers": {"trousers_red", "trousers_blue"}, "hats": {"hat_01", "hat_02"} } you should be able to easily swap between the different clothing.
As was mentioned on Slack you have couple of choices:
Layout a number of gui box nodes in the positions of the different character parts, then change the image used on a box node using gui.play_flipbook(hat_node, “tophat”)
Layout a number of game objects in the positions of the different characters (or optionally one game object with many sprites), then change the sprite image using sprite.play_animation("#hatsprite", “tophat”)
If you have a lot of images, then you have a bit more flexibility in memory management if you decide to use sprites (through dynamic load of game object factories). This require some changes to how #2 is done, but in general the idea is still the same.
I think I should be able to help you here, as I have used similar logic many a times in almost all my projects.So, I just created an example for this: animal_dressups.zip (417.9 KB)
Hope that it solves you query.