在这里,我正在创建一个按钮,该按钮具有按下按钮时调用的函数
local politeButton = widget.newButton
{
left = 35,
top = 335,
width = 70,
height = 70,
defaultFile = "images/politeRu.png",
overFile = "images/politeWhiteRu.png",
onPress = politeGenerator,
}
这是功能(实际上它在按钮上方编码)
math.randomseed(os.time())
local function politeGenerator()
local firstRandomPart = math.random(1,3)
local secondRandomPart = math.random(1,3)
local thirdRandomPart = math.random(1,3)
local firstComplPart = {"I love", "I need", "I beg"}
local secondComplPart = {" you like mad ", " the color of your eyes ", " your lips "}
local thirdComplPart = {"and I wish you are going to be mine!", "and I am shivering!", "and this is all I want!"}
local politeCompliment = firstComplPart[firstRandomPart]..secondComplPart[secondRandomPart]..thirdComplPart[thirdRandomPart]
local complimentItself = display.newText(politeCompliment, 30, 150, 200, 200, "Lobster", 18)
end
好的,现在我在模拟器中看到了一些随机生成的文本。但是当我再次按下按钮时,旧文本不会消失,新文本会出现在旧文本上,依此类推。但是每次按下按钮时我都需要覆盖文本。我试过了event.phase == "began"
,我试过了,complimentItself:removeSelf()
但都是徒劳的。有人可以帮忙吗?我只是不明白为什么当我按下按钮时变量没有被覆盖。