display.newText blinks when updating UTF8 characters

I’m deving dialogue UI which display characters one by one with given delay and text.
the issue here is the “display.newText” blinks when updating UTF8 characters in simulator.
( using macOS Big Sur v11.7.1 )

Here is the code:


local _testStr = "♡ 你好,World ♡"
-- local _testStr = "こんにちは World"
-- local _testStr = "헬로 World"
local _textLen = string_len( _testStr )

local _opt = {
    text = "",
    x = display.contentCenterX,
    y = display.contentCenterY,
    width = 420,
    fontSize = 48,
    align = "left",
}
local _ttfText = display.newText(_opt)

local _cnt = 1;
timer.performWithDelay( 200, 
    function() 
        _cnt = _cnt + 1
        _ttfText.text = string.sub( _testStr, 1, math.min( _cnt, _textLen ))
    end,100
)

is there any solution to fix this? thanks in advance.

If they are UTF8 strings, you may want to try using, “utf8.len” and “utf8.sub”. For example,

local _textLen = utf8.len( _testStr )
_ttfText.text = utf8.sub( _testStr, 1, math.min( _cnt, _textLen ) )

Please see Solar2D Documentation — Plugins | UTF-8 for details on the various UTF8 functions.

PS> Not sure about macOS. I can only try your snippets on my simulator/Windows. I only have Windows PC. Hope it helps, anyway.

1 Like

It fixed the blinking issue.

Thank a lot, you saved the day! :grinning_face_with_smiling_eyes:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.