I have a game where I need to change images in a random order.
Imagine a face of a person.
where the face is one object, and the hair it’s another object.
What I would like to do, is tap on the hair, and I will get a different image hair (long, short, yellow, brown and so on) in the same place, so kids can change the look of the person
every time I tap.
and a different image face (happy, sad, scared…) – you get the idea.
I guess I need a table with many images – something like this – correct?
local hairTable {"long.png", "short.png", "yellow.png", "brown.png",} local faceTable {"happy.png", "sad.png", "scared.png", }
then I need a function like this to touch the object
local touchObject = function (event) local obj = event.target if event.phase == "ended" then if obj.name == "face" then --here I don't know how to do it end if obj.name == "hair" then --here I don't know how to do it end end return true end
But because both of them are --obj-- I don’t know how to distinguish them.
and also how to get the random images from the table.
Do I need something like this?
hair.brown.isVisible = false
hair.yellow.isVisible = true
but how do I get them from the table, in a random order
or like this
Do I need something like this?
hair[3].isVisible = false
hair[1].isVisible = true
I’m very confused
I have been working with tables for about 2 months
but I just copy and paste functions
I still don’t really get it.
I just hear words like – the 4th element, like table[4]
or thinks like that, but still not clear – I guess I’m close
but I need help