Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Using TextField "sample" parameter with cached characters — Gideros Forum

Using TextField "sample" parameter with cached characters

totebototebo Member
edited September 2016 in General questions
See code below and attached project. Is this expected, or a bug?
--[[
 
	This code illustrates two bugs when using a font with cached characters:
 
	1. Alignment fails 
	2. Textfields appear to sometimes jump when drawn
 
	When no text is cached, it works as expected.
 
--]]
 
local textfield1
local textfield2
 
function displayText()
 
	-- Line to align TextField
	local shape = Shape.new()
	shape:setLineStyle(1, 0x00ff00, 0.5)
	shape:beginPath()
	shape:moveTo(0,0)
	shape:lineTo(320, 0)
	shape:endPath()
	shape:setPosition(0, 100)
	stage:addChild(shape)
 
	-- Creating and caching text of first textfield, setting line height to character"0"
	if textfield1 then
		textfield1:removeFromParent()
	end	
	local str = "One"
	local font = TTFont.new("OpenSans-ExtraBold.ttf", 30, str) -- Works if "str" parameter is removed
	textfield1 = TextField.new(font, str, "0") -- Works if "0" parameter is removed
	textfield1:setPosition( 0, 100 )
	stage:addChild( textfield1 )
 
	-- Creating and caching text of second textfield, setting line height to character"0"
	if textfield2 then
		textfield2:removeFromParent()
	end		
	local str = "Two"
	local font = TTFont.new("OpenSans-ExtraBold.ttf", 55, str) -- Works if "str" parameter is removed
	textfield2 = TextField.new(font, str, "0") -- Works if "0" parameter is removed
	textfield2:setPosition( 100, 100 )
	stage:addChild( textfield2 )
 
end
 
local timer = Timer.new( 100 )
timer:addEventListener( Event.TIMER,
	function()
		displayText()
	end
)
timer:start()
zip
zip
LineHeight.zip
119K
My Gideros games: www.totebo.com

Comments

Sign In or Register to comment.