2
我正在製作一款遊戲,通過按圖像來收集分數。按下圖像並重新生成新圖像並不成問題,但爲分數添加點會導致一些問題。當我按下圖像時,得分不會隨點數而更新。我正在使用此分數模塊http://coronalabs.com/blog/2013/12/10/tutorial-howtosavescores/使用分數模塊添加分數
local score_mod = require("score")
math.randomseed(os.time())
local scoreText = score_mod.init({
fontSize = 70,
font = native.systemFont,
x = display.contentCenterX + 50,
y = display.contentCenterY + 170,
filename = "scorefile.txt"
})
scoreText:setTextColor((232/255), (216/255), (32/255))
local function Game()
local images ={
{name = "Icon.png", points = 1},
{name = "Icon-mdpi.png", points = 2},
{name = "Icon-xhdpi.png", points = 3},
{name = "Icon-ldpi.png", points = 4},
{name = "Icon-Small-50.png", points = 5}
}
local numRows = 3
local numCols = 2
local blockWidth = display.contentCenterX/2.2
local blockHeight = display.contentCenterY/2
local row
local col
local imgDataArray = {}
function imagePress (event)
if event.phase == "began" then
local x = event.target.x
local y = event.target.y
event.target:removeSelf()
score_mod.score = score_mod.score + images[event.target.imgNumber].points
function nextImages(x, y)
local nextRandomImg = math.random(1,5)
local nextImage = display.newImage(images[nextRandomImg].name, x, y)
nextImage:addEventListener("touch", imagePress)
nextImage.imgNumber = nextRandomImg
table.insert(imgDataArray, image)
end
local nextDelay = function() return nextImages(x, y) end
timer.performWithDelay(2000, nextDelay, 1)
end
return true
end
function makeImage()
for row = 1, numRows do
for col = 1, numCols do
local x = (col - 1) * blockWidth + 120
local y = (row + 1) * blockHeight - 160
local randomImage = math.random(1, 5)
local image = display.newImage(images[randomImage].name, x, y)
image.imgNumber = randomImage
image.imgX = x
image.imgY = y
image:addEventListener("touch", imagePress)
table.insert(imgDataArray, image)
end
end
end
makeImage()
end
Game()
非常感謝!
你不應該實際上使用'score_mod.set'? – hjpotter92
這也是我最初的想法,但它給了我一個錯誤。嘗試在字段'set'上執行算術(函數值) –
'score_mod.set'是一個函數,您可以使用新分數值調用它。或者你使用'score_mod.add'爲分數添加一個值。鏈接的頁面在最後談到了這一點,並鏈接到示例應用程序。 –