I’m trying a make a little tap game on the simulator, what I’m trying to make happen is when one of the rects is tapped say the purple rect the message in the simulator would read Purple Rect Tapped. In my mind when the purple rect is tapped that rect is now selected to be used in the game.
What happens when I tap any of the rects all 3 colors are written out; I thought that I could figure out how to change some of the code on the multiple taps info in corona labs, but it’s not working out the way I hoped it would.
local function tapListener(event) local o=event.target print(o.color.." Rect Tapped: "..tostring(o)) return true end local yellowRect=display.newRect(...) yellowRect:setFillColor(...) yellowRect.color="yellow" \<\<-- important yellowRect:addEventListener("tap",tapListener) same with purple and green etc...
The “o” is a local variable to have a shortcut to the element “event.target”. It’s just a name, you can use other term like “myObject” for example.
For the background, you can use
display.setDefault( "background", 0, 0, 1 ) \<--for blue
So in the end you have :
local function tapListener(event) local myChoice=event.target print(myChoice.color.name.." Rect Tapped: "..tostring(myChoice) display.setDefault( "background", unpack(myChoice.color.rgb) ) return true end local greenRect=display.newRect(...) greenRect:setFillColor(0,1,0) greenRect.color={name="green",rgb={0,1,0}}
local function tapListener(event) local o=event.target print(o.color.." Rect Tapped: "..tostring(o)) return true end local yellowRect=display.newRect(...) yellowRect:setFillColor(...) yellowRect.color="yellow" \<\<-- important yellowRect:addEventListener("tap",tapListener) same with purple and green etc...
The “o” is a local variable to have a shortcut to the element “event.target”. It’s just a name, you can use other term like “myObject” for example.
For the background, you can use
display.setDefault( "background", 0, 0, 1 ) \<--for blue
So in the end you have :
local function tapListener(event) local myChoice=event.target print(myChoice.color.name.." Rect Tapped: "..tostring(myChoice) display.setDefault( "background", unpack(myChoice.color.rgb) ) return true end local greenRect=display.newRect(...) greenRect:setFillColor(0,1,0) greenRect.color={name="green",rgb={0,1,0}}