Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
MovieClip width - Gideros Forum

MovieClip width

zvardinzvardin Member
edited March 2013 in General questions
I was animating some text where I have a pass in a string and have MovieClips moving each character individually. To position the moving text, I placed them all in a parent sprite. My simple function is here:
local function waveText(str, font, color)
	local i = 1
	local x = 0
	local xOffset = 5
	local grp = Sprite.new()
	local mc,t,w
	local yMove = 25
	local tOffsetInc = 5
	local tOffset
	local t1,t2,t3
	for c in str:gmatch(".") do
		if c ~= " " then
			t = TextField.new(font, c)
			w = t:getWidth()
			tOffset = (i-1)*tOffsetInc
			t1,t2,t3 = tOffset+1,tOffset+50,tOffset+100
			mc = MovieClip.new{
			w = 15
		x = x + w + xOffset
		i = i + 1
	return grp
However, it's hard to center because grp:getWidth() always returns 29 so it seems the MovieClips don't fetch the width of what they're manipulating. If I add the TextField objects instead of the MovieClips I get the width expected but that has other side effects since then the text appears before it is animated. I plan to return the width I'm calculating in my function, but I just wanted to see if this was intended functionality or if there is an easier way to handle a scenario like this. Thanks for any insight!


  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @zvardin quick fix would be to add the textfield object and set it to invisible, then you can manipulate text inside invisible textField just so the parent could return the needed dimensions.
  • Yeah, I thought of that but in that case I just store the width I'm calculating to position each character anyhow. I figured that would be better since all copies of TextField would receive events (although that would be relatively minor I imagine). What's interesting is from the quick test I did, hitTestPoint() seems to work on that area, but getBounds() also returns incorrect results.
Sign In or Register to comment.