Button!

How can i change the color of the play button (local play) when i touch it???

  module(..., package.seeall)       function new() local localGroup = display.newGroup()   local bg = display.newImage("bg.png")   local play = display.newImage("button1.png") play.x = W/2 play.y = H/2 play.scene = "levelSel"   local playText = display.newText("Play", 0, 0, "Arial", 95) playText.x = play.x playText.y = play.y       localGroup:insert(bg) localGroup:insert(play)           function changeScene(e) if e.phase == "ended" then director:changeScene(e.target.scene) end end       play:addEventListener("touch", changeScene) return localGroup   end  

Here is a small example of how this can be done. In your case you would make another play image with another color.

local centerXcord = display.contentCenterX local centerYcord = display.contentCenterY object = display.newRect(centerXcord, centerYcord, 32, 32) --Sets objects color to orange. object:setFillColor( 255, 128, 0 ) function object:touch( event ) if event.phase == "began" then --Sets objects color to yellow object:setFillColor( 200, 200, 0 ) return true end end object:addEventListener( "touch", object )

ok thanks :slight_smile:

How can i write a generic function for all  buttons in the game?

Well I guess you would make a table to hold your buttons and then do the same as up top.

Here is a small example of how this can be done. In your case you would make another play image with another color.

local centerXcord = display.contentCenterX local centerYcord = display.contentCenterY object = display.newRect(centerXcord, centerYcord, 32, 32) --Sets objects color to orange. object:setFillColor( 255, 128, 0 ) function object:touch( event ) if event.phase == "began" then --Sets objects color to yellow object:setFillColor( 200, 200, 0 ) return true end end object:addEventListener( "touch", object )

ok thanks :slight_smile:

How can i write a generic function for all  buttons in the game?

Well I guess you would make a table to hold your buttons and then do the same as up top.