Avoid padding on TextActor

36 views
Skip to first unread message

Iker Vázquez

unread,
Jul 9, 2013, 3:57:42 AM7/9/13
to caa...@googlegroups.com
Hi!

If I create a textactor with the following code:

function generateVal(val, T) { 
 var text = new CAAT.TextActor(). 
 setFont("300px sans-serif").
 setFillStyle('red'). 
 setText(val). 
 setFrameTime(scene.time + T, 2000). 
 setOutline(true). 
 cacheAsBitmap(). 
 setAlpha(0). 
 addBehavior(new CAAT.AlphaBehavior().setFrameTime(scene.time + T, 1000).setValues(0, 1). 
   setInterpolator(new CAAT.Interpolator(). 
   createExponentialInInterpolator(3, true))) 
 text.setLocation((container.width / 2) - (text.width / 2), (container.height / 2) - (text.height / 2)); 
return text; 
}

I get a padding over the text that breaks the position. Both methods text.height and text.textHeight returns 720px.

Is there any way to get the correct height of the text?

Regards,
Iker

Ba Chấm

unread,
Jul 9, 2013, 6:46:13 AM7/9/13
to caa...@googlegroups.com
Hi!

Try textActor.calcTextSize(director)

Regards,



2013/7/9 Iker Vázquez <ike...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "CAAT javascript framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caatjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Iker Vázquez

unread,
Jul 11, 2013, 3:29:42 AM7/11/13
to caa...@googlegroups.com
I try it but it stills returns a height of 720:

  1. fontDataObject
    1. ascent599
    2. descent121
    3. height720

  2. (The first code was bad. The setFont is 600 not 300) 
I need to set the character's position at the center of the screen, but I have minus and plus operators and they appear lower than I need.

Regards,
Iker

hyperandroid

unread,
Jul 11, 2013, 4:40:34 AM7/11/13
to caa...@googlegroups.com
Better post an example and or screenshot.
Tge demos have plenty examples of text manipulation.

Thanks.
--

Iker Vázquez

unread,
Jul 11, 2013, 6:34:15 AM7/11/13
to caa...@googlegroups.com



I added a setFillStyle('red') to see the behavior. I would like to avoid the red zone and get que height/width of just the sign. Is it possible to do this? The W/H of the director is 1024x768. Same thing for the actor's container. 

Regards,

Iker

To unsubscribe from this group and stop receiving emails from it, send an email to caatjs+unsubscribe@googlegroups.com.

hyperandroid

unread,
Jul 11, 2013, 9:45:21 AM7/11/13
to caa...@googlegroups.com
I mean post the code you are using.
As Bo says calcTwxtSize measures text's bounds.
If you want to change text's color use setTextFillStyle. You can open demo1 and see how text is handled in the swinging panel.
To unsubscribe from this group and stop receiving emails from it, send an email to caatjs+un...@googlegroups.com.

Iker Vázquez

unread,
Jul 11, 2013, 9:54:00 AM7/11/13
to caa...@googlegroups.com
:-D

The code to generate the actors:

function generateVal(val, T) { 
 var text = new CAAT.TextActor().
 setText(val).
 setFont("600px Arial").
 setFillStyle('red'). // Testing purposes
 calcTextSize(game.director). 
 setTextAlign("middle").
 setFrameTime(scene.time + T, 2000).
 setOutline(true).
 cacheAsBitmap().
 setAlpha(0).
 addBehavior(new CAAT.AlphaBehavior()
                   .setFrameTime(scene.time + T, 1000)
                   .setValues(0, 1)
                   . setInterpolator(new CAAT.Interpolator()
                                          . createExponentialInInterpolator(3, true))) 
 text.setLocation((container.width / 2) - (text.width / 2),(container.height / 2) - (text.height / 2)); 
 return text; 
 }

With this code i get:

text.textHeight = 720
text.height = 720

Regards,
Iker

Iker Vázquez

unread,
Jul 15, 2013, 11:25:04 AM7/15/13
to caa...@googlegroups.com
Well, I fix it by using images for the signs (+,-) instead of a TextActor. calcTextSize always returns 720px height for every text.

Regards,
Iker


Ba Chấm

unread,
Jul 15, 2013, 11:50:53 AM7/15/13
to caa...@googlegroups.com
I just write something

window.onload = function () {
    var director = new CAAT.Foundation.Director().initialize(800, 600);
    var scene = director.createScene();

    var text = new CAAT.Foundation.UI.TextActor().
                    setFont("30px sans-serif").
                    setText("Qwerty").
                    setTextFillStyle("red").
                    calcTextSize(director).
                    cacheAsBitmap();

    scene.addChild(text.setLocation(200, 200));

    console.log(text.height); // 36
    console.log(text.width); // 93
    CAAT.loop();
}
hope this help


2013/7/15 Iker Vázquez <ike...@gmail.com>
Well, I fix it by using images for the signs (+,-) instead of a TextActor. calcTextSize always returns 720px height for every text.

Regards,
Iker


--
You received this message because you are subscribed to the Google Groups "CAAT javascript framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caatjs+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages