It looks like you're new here. If you want to get involved, click one of these buttons!
function TextField:init(...) local arg = {...} --typewriter effect local function typewriter(str, speed) local i = 0 local in_str = str local str_length = string.len(in_str) local typeSpeedTimer = Timer.new(speed, str_length) local function getString() if i <= str_length then i = i+1 --1 is the number of characters to add each time local out_str = string.sub(in_str, 1, i) self._text:setText(out_str) self._text:setVisible(true) end end typeSpeedTimer:addEventListener(Event.TIMER, getString) typeSpeedTimer:start() end self._text = _TextField.new(...) self._text:setVisible(false) self:addChild(self._text) self._font = arg[1] --if string and speed are specified if arg[2] and arg[3] then local str = arg[2] local typewritespeed = arg[3] typewriter(str, typewritespeed) end self._offsetX = 0 self._offsetY = 0 local baseX, baseY = self._text:getBounds(stage) self._text:setPosition(-baseX, -baseY) end |
local testtxt= TextField.new(nil, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 10) stage:addChild(testtxt) |
Likes: MoKaLux
Comments
Likes: pie
Likes: MoKaLux
there could be an issue if you use non ascii chars. You’d better use utf8.len and utf8.sub to deal with multi byte characters.
Likes: MoKaLux
Likes: MoKaLux
Likes: MoKaLux, pie