
Share Your Code
Browse Code
- All (907)
-
(94)
-
(85)
-
(44)
-
(4)
-
(42)
-
(137)
-
(21)
-
(41)
-
(13)
-
(65)
-
(151)
-
(210)
Simple graphical timed score
Hi
for this example you need a 25x29 transparent png for every number from 0 to 9, named n#.png. This example is for a 6 digits score.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | display.setStatusBar (display.HiddenStatusBar) --Define variables local imatgesScore= {} local scoredigit={} local scoreResta=0 score=0 --Initialize scoredigits to Zero for m=0,5,1 do scoredigit[m]=0 local nomImatge ="n"..tostring(scoredigit[m])..".png" imatgesScore[m] =display.newImage(nomImatge) imatgesScore[m].x=20+25*(6-m) end --Updates the score local function actualitzaMarcador(scoreTotal) for m=5,0,-1 do scoredigit[m]=math.floor(scoreTotal/10^m) scoreResta=scoredigit[m]*10^m scoreTotal=scoreTotal-scoreResta end for n=0,5,1 do local nomImatge ="n"..tostring(scoredigit[n])..".png" imatgesScore[n]:removeSelf() imatgesScore[n] =display.newImage(nomImatge) imatgesScore[n].x=20+25*(6-n) end end --Timed score, every half second adds 10 to score local function sumaMarcadorPerTemps(event) score=score+10 actualitzaMarcador (score) end timer.performWithDelay(500, sumaMarcadorPerTemps,0) |
- Type:
- Tags:
Excelente amigo, justo lo que necesitaba, sencillo y perfecto.