Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
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)
			t:setTextColor(color)
			--t:setX(x)
			w = t:getWidth()
			tOffset = (i-1)*tOffsetInc
			t1,t2,t3 = tOffset+1,tOffset+50,tOffset+100
 
			mc = MovieClip.new{
				{t1,t2,t,{y={-yMove,yMove,"inOutSine"}}},
				{t2,t3,t,{y={yMove,-yMove,"inOutSine"}}}
			}
			mc:setGotoAction(t3,t1)
			mc:setX(x)
			grp:addChild(mc)
		else
			w = 15
		end
		x = x + w + xOffset
		i = i + 1
	end
	return grp
end
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!

Comments

  • 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.