不确定如何在Corona SDK中设置圆形填充颜色。

这是我编写的代码,旨在尝试设置circle.fillColor属性。if语句无效。有人能提供建议吗?

function cicle:touch( event )
    --if (event.phase == "began") and (circle.fillColor == red) then
     score = score + 1
     playerScore.text = "Score: " .. score
    --end
  end
点赞
用户7147481
用户7147481

我认为你打错了。函数应该写成 circle:touch,而不是 cicle:touch。

在这里,你正在检查 circle.fillColor 是否是一个变量(red)。如果您以这种方式执行,您需要创建变量 red 并将字符串“red”添加到它中。但是这里有一个更简单的方法:

local score
local circle = display.newCircle(display.contentCenterX, display.contentCenterY, 20)

circle.fillColor = "red"

function circleTouch( event )
     if (event.phase == "began") and (circle.fillColor == "red") then
                  score = score + 1
                  playerScore.text = "Score: " .. score .. ""
          end
  end
  circle:addEventListener("touch", circleTouch)
2017-02-23 19:57:41