【问题标题】:Unsure how to set circle.fillColor in Corona SDK不确定如何在 Corona SDK 中设置 circle.fillColor
【发布时间】:2017-02-24 03:57:41
【问题描述】:

这是我为尝试设置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

【问题讨论】:

  • 但是“如果”不起作用
  • 添加更多代码并具体说明您所说的内容?
  • 您需要添加更多代码并解释您在运行应用程序时遇到的错误。电晕形状(在您的情况下为圆形)没有 fillColor 属性或功能。
  • 您的意思可能是字符串"red" 而不是red

标签: lua coronasdk


【解决方案1】:

我认为你有错字。函数说 cicle:touch 但我认为你想要 circle:touch。

在这里,您正在检查 circle.fillColor 是否为变量(红色)。如果您这样做,您需要创建变量 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多