I've tried to add a scoring to my game, using numbers. My score is composed of 5 numbers as you can see on the image below
To display the starting score (00000), i used 5 images (scoreB.png is the image of the number zero) :
score_nul_1 = display.newImage( "scoreB.png")
score_nul_1.x = score_title.x+180---center the sprite horizontally
score_nul_1.y = 35 --center the sprite vertically
screenGroup:insert(score_nul_1)
score_nul_1.isVisible=true
score_nul_2 = display.newImage( "scoreB.png")
score_nul_2.x = score_title.x+220---center the sprite horizontally
score_nul_2.y = 35 --center the sprite vertically
screenGroup:insert(score_nul_2)
score_nul_2.isVisible=true
score_nul_3 = display.newImage( "scoreB.png")
score_nul_3.x = score_title.x+263---center the sprite horizontally
score_nul_3.y = 35 --center the sprite vertically
screenGroup:insert(score_nul_3)
score_nul_3.isVisible=true
score_nul_4 = display.newImage( "scoreB.png")
score_nul_4.x = score_title.x+306---center the sprite horizontally
score_nul_4.y = 35 --center the sprite vertically
screenGroup:insert(score_nul_4)
score_nul_4.isVisible=true
score_nul_5 = display.newImage( "scoreB.png")
score_nul_5.x = score_title.x+349---center the sprite horizontally
score_nul_5.y = 35 --center the sprite vertically
screenGroup:insert(score_nul_5)
score_nul_5.isVisible=true
Then, i used a sprite to change the number from 1 to 9 :
local sheetData_scorea = { width=43, height=53, numFrames=10, sheetContentWidth=430, sheetContentHeight=53}
local mySheet_scorea = graphics.newImageSheet( "scoreA.png", sheetData_scorea )
local sequenceData_scorea =
{
{name = "0", frames={10}, loopCount=0, time=1000 },
{name = "1", frames={1}, loopCount=0, time=1000 },
{name = "2", frames={2}, loopCount=0, time=1000 },
{name = "3", frames={3}, loopCount=0, time=1000 },
{name = "4", frames={4}, loopCount=0, time=1000 },
{name = "5", frames={5}, loopCount=0, time=1000 },
{name = "6", frames={6}, loopCount=0, time=1000 },
{name = "7", frames={7}, loopCount=0, time=1000 },
{name = "8", frames={8}, loopCount=0, time=1000 },
{name = "9", frames={9}, loopCount=0, time=1000 },
{name = "10", frames={10}, loopCount=0, time=1000 },
}
score_a1 = display.newSprite( mySheet_scorea, sequenceData_scorea)
score_a1.x = score_title.x+306--center the sprite horizontally
score_a1.y = 35 --center the sprite vertically
screenGroup:insert(score_a1)
score_a1.isVisible=false
And to update the score, i use this function :
if mydata.score >=100 and mydata.score<1000 then
score_nul_4.isVisible=false
score_nul_3.isVisible=false
end
if mydata.score < 100 then
score_a.isVisible=true
score_nul_4.isVisible=false
score_a.x = score_title.x+306
score_a:setSequence(i)
score_a:play()
i = i +1
end
if mydata.score>=100 then
i=1
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(b)
score_a1:play()
b=b+1
end
if mydata.score>=200 then
i=2
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(c)
score_a1:play()
c=c+1
end
if mydata.score>=300 then
i=3
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(d)
score_a1:play()
d=d+1
end
if mydata.score>=400 then
i=4
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(e)
score_a1:play()
e=e+1
end
if mydata.score>=500 then
i=5
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(f)
score_a1:play()
f=f+1
end
if mydata.score>=600 then
i=6
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(g)
score_a1:play()
g=g+1
end
if mydata.score>=700 then
i=7
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(h)
score_a1:play()
h=h+1
end
if mydata.score>=800 then
i=8
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(j)
score_a1:play()
j=j+1
end
if mydata.score>=900 then
i=9
score_a.x = score_title.x+263
score_a.isVisible=true
score_a:setSequence(i)
score_a:play()
score_a1.isVisible=true
score_a1:setSequence(k)
score_a1:play()
k=k+1
end
So my question is : Is it possible to have more "simple" way to make my scoring using images ?