Setting the fill color on an image in an event does not change the fill color, unless you change another property that forces it to update. Vector display objects do update fill color normally
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | local defaultColor = {255,255,255,255 } local touchColor = {255,100,100,255 } ---- CHANGING FILL COLOR IN EVENT WORKS ON CIRCLE DISPLAY OBJECT -- local function buttonTouchEvent( event ) local phase = event.phase local target = event.target if "began" == phase then target:setFillColor(touchColor[1],touchColor[2],touchColor[3]) target.isFocus = true display.getCurrentStage():setFocus( target, event.id ) elseif "ended" == phase or "cancelled" == phase then target:setFillColor(defaultColor[1],defaultColor[2],defaultColor[3]) display.getCurrentStage():setFocus( target, nil ) target.isFocus = false end end local button1 = display.newCircle( display.contentWidth/2, display.contentHeight/2 - 200, 50 ) button1.x ,button1.y = display.contentWidth/2, display.contentHeight/2 - 200 button1:addEventListener( "touch", buttonTouchEvent ) ---- CHANGING FILL COLOR IN EVENT ON IMAGE DISPLAY OBJECT DOES NOT -- local button2 = display.newImage("waveCircle.png") button2.x ,button2.y = display.contentWidth/2, display.contentHeight/2 button2:addEventListener( "touch", buttonTouchEvent ) ---- UNLESS YOU DO THIS (forcing an update?) -- local function buttonTouchEventFix( event ) local phase = event.phase local target = event.target if "began" == phase then target.isVisible = false target.isVisible = true -- fix target:setFillColor(touchColor[1],touchColor[2],touchColor[3]) target.isFocus = true display.getCurrentStage():setFocus( target, event.id ) elseif "ended" == phase or "cancelled" == phase then target:setFillColor(defaultColor[1],defaultColor[2],defaultColor[3]) target.alpha = 0.5 target.alpha = 1 --another fix display.getCurrentStage():setFocus( target, nil ) target.isFocus = false end end local button3 = display.newImage("waveCircle.png") button3.x ,button3.y = display.contentWidth/2, display.contentHeight/2 + 200 button3:addEventListener( "touch", buttonTouchEventFix ) |
Hi Ernest,
We saw a bug report for this recently and I believe we are still looking into it; if I can find out any news I will let you know.
Thanks,
Peach :)