bitmap font with real time changing varaible

i tried most of the bitmap fonts and non of them can help in this .

most of them work fine when you just use them to print text using “text”  but when i use them in printing time or score  they just didnot work

for example

scoreText = display.newText(sceneGroup,score,screenLeft+20,screenTop+20, native.systemFontBold, 30) scoreText:setTextColor(1, 0, 0) TapToKill = function ( event ) -- here we have to add the tap function if event.target.sequence == "whatever" then event.target:setSequence("falldown") event.target:play() audio.play (Soundclicks) transition.to ( event.target, {time=500,x=centerX,y=centerY,alpha=0,tag = "animationBlock"} ) score = score + 1 scoreText.text = score event.target:removeSelf() elseif event.target.sequence == "falldown" then event.target:removeEventListener ( "tap" , TapToKill ) end return true end

this work fine to display score once i tap on the subject

but when i try to use for ex: Font-Manager-revamped-version  , the score stuck to 0 only

mostly i face these issue with dynamic changing variable that need to be printed in the screen like time or score , if i use

scoreText = display.newBitmapText(tostring(score),screenLeft+20,screenTop+20,"retrofont",50)

it just didnot work always show 0

I decided not to use Bitmap Fonts . i guess it would be more complicated and not useful.

using a custom font is more useful and more elastic to handle .

Hi,

I always use bitmap fonts to display my score counter at the end of a level. You need to write some code but it should not be that difficult to implement.

Hi Thomas , well i could show the score at the end of the level easly using myData file and json  . but that is not what i wanted to ask here

what i wanted to have is the dynamic changing score at the top of your level when it still playing .

You asked about implementing a dynamic score counter using bitmap fonts. Wether you use it during the level or as a bonus counter after the level is irrelevant, because it is 99% the same technique. I just stated that I personally always use a dynamic bitmap font counter at the end of my level and that it is fairly easy.

1: make an imagesheet with the numbers 0 to 9

2: convert your score into a string with leading zero (so score 950 becomes “000950”)

3: create a displayGroup containing six images for 6 digits.

4: read out the ASCII code of every character in your string score from left to right.

5: for each letter: subtract the right amount from the ASCII codes so you end up with values from 1 to 10.

6: for each letter: set the frame for each letter to the value you get in step 5

7: if you don’t want the leading zeros, use some logic that set the first images to alpha 0 as long as they are zeroes.

You can put step 4 to 7 in one function that you can call each time your score updates.

Voila!

This should help you out:

local score7digits = string.format("%07d", UI.scoreCounterCurrent) for i = 1, 7 do local digitCode = string.byte(score7digits, i)-48 UI.scoreCounterGroup[i]:setFrame(UI.sheetInfo:getFrameIndex("Number-"..digitCode)) end

I decided not to use Bitmap Fonts . i guess it would be more complicated and not useful.

using a custom font is more useful and more elastic to handle .

Hi,

I always use bitmap fonts to display my score counter at the end of a level. You need to write some code but it should not be that difficult to implement.

Hi Thomas , well i could show the score at the end of the level easly using myData file and json  . but that is not what i wanted to ask here

what i wanted to have is the dynamic changing score at the top of your level when it still playing .

You asked about implementing a dynamic score counter using bitmap fonts. Wether you use it during the level or as a bonus counter after the level is irrelevant, because it is 99% the same technique. I just stated that I personally always use a dynamic bitmap font counter at the end of my level and that it is fairly easy.

1: make an imagesheet with the numbers 0 to 9

2: convert your score into a string with leading zero (so score 950 becomes “000950”)

3: create a displayGroup containing six images for 6 digits.

4: read out the ASCII code of every character in your string score from left to right.

5: for each letter: subtract the right amount from the ASCII codes so you end up with values from 1 to 10.

6: for each letter: set the frame for each letter to the value you get in step 5

7: if you don’t want the leading zeros, use some logic that set the first images to alpha 0 as long as they are zeroes.

You can put step 4 to 7 in one function that you can call each time your score updates.

Voila!

This should help you out:

local score7digits = string.format("%07d", UI.scoreCounterCurrent) for i = 1, 7 do local digitCode = string.byte(score7digits, i)-48 UI.scoreCounterGroup[i]:setFrame(UI.sheetInfo:getFrameIndex("Number-"..digitCode)) end