Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Change Font of newText after created
Started by rithy_huon007 Aug 09 2013 01:30 AM

- - - - -
12 replies to this topic
newtext font
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

rithy_huon007

[GLOBAL: userInfoPane.html]
rithy_huon007
  • Observer

  • 20 posts
  • Corona SDK

HI,

 

Is there a way to change font using newText() after object is created?

For example, i have

myText = display.newText("Hello World!", 0, 0, native.systemFont, 16and a Button.

 

When i touch the button, i want to change text font to "Helvetica" without recreate the object.

Is there a way to do so?

 

PS: i can't access font via myText.font

 

Thanks,



[TOPIC: post.html]
#2

jonjonsson

[GLOBAL: userInfoPane.html]
jonjonsson
  • Corona Geek

  • 1,051 posts
  • Corona SDK

Hi,

 

no thats not possible. Best to just hide the original and create a new one in Helvetica.



[TOPIC: post.html]
#3

jmaher

[GLOBAL: userInfoPane.html]
jmaher
  • Enthusiast

  • 65 posts
  • Corona SDK

Actually, the docs:

http://docs.coronalabs.com/api/type/TextBox/font.html

http://docs.coronalabs.com/api/library/native/newFont.html

 

indicate you can change the .font property of newText objects using native.newFont() but I haven't been able to get it to work.

 

Anyone else have this working?



[TOPIC: post.html]
#4

jstrahan

[GLOBAL: userInfoPane.html]
jstrahan
  • Corona Geek

  • 1,926 posts
  • Corona SDK

That's for native.newTextBox and native.newTextField not display.newText

[TOPIC: post.html]
#5

jmaher

[GLOBAL: userInfoPane.html]
jmaher
  • Enthusiast

  • 65 posts
  • Corona SDK

That second doc specifically says:

"You can also pass it as a parameter to the display text objects in the display.newText() function."

 

That led me to believe that you could also use it to make a change via the .font property, but maybe not...



[TOPIC: post.html]
#6

jstrahan

[GLOBAL: userInfoPane.html]
jstrahan
  • Corona Geek

  • 1,926 posts
  • Corona SDK

I can see how that could be confusing

[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

I've asked for the docs to be updated.



[TOPIC: post.html]
#8

jmaher

[GLOBAL: userInfoPane.html]
jmaher
  • Enthusiast

  • 65 posts
  • Corona SDK

Rob, is there any reason this couldn't be done?

 

After all, you can change the .size property, which also forces the font bitmap to be redrawn.



[TOPIC: post.html]
#9

jstrahan

[GLOBAL: userInfoPane.html]
jstrahan
  • Corona Geek

  • 1,926 posts
  • Corona SDK

i would think its cause corona was built as a game engine and there's not much need to change the font of text after its created. but now as developers are starting to use corona for more business apps i could see more need for it



[TOPIC: post.html]
#10

jmaher

[GLOBAL: userInfoPane.html]
jmaher
  • Enthusiast

  • 65 posts
  • Corona SDK

Yes, and from a technical standpoint, they already have a property (.size) that can be changed, and that internally forces a redraw of the whole font bitmap, which is what a change to the typeface would also need to do.



[TOPIC: post.html]
#11

Jam Paraiso

[GLOBAL: userInfoPane.html]
Jam Paraiso
  • Enthusiast

  • 98 posts
  • Corona SDK

create both text on the first place, then with some logic hide the second or the first using "object.alpha"

then if you press the button you can just change the alpha's of the text to hide and reveal them

 

Jam



[TOPIC: post.html]
#12

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,539 posts
  • Enterprise

Changing the font size probably is just a scaling thing.  The display.newText() is renedered as an OpenGL texture and as such once it's rendered it's the same as an image, rectangle, etc.  So changing scale is easy, but to change the font means dropping the texture and re-creating it.   (I'm speculating on this.  I'll need to ask engineering to make sure).



[TOPIC: post.html]
#13

jmaher

[GLOBAL: userInfoPane.html]
jmaher
  • Enthusiast

  • 65 posts
  • Corona SDK

Well, here is what the "Wednesday FAQs" blog entry by Tom Newman on June 26 said:

 

2. I’m moving text around on the screen, will that slow down my app?

Moving or scaling text objects does not slow down Corona SDK. If you are changing the text, the bit map needs to be recreated, which can impact the frame rate. The same is true when changing the font size or the font type. These all require a new bit map and may affect performance.
 
This answer was another reason I thought this was possible in the first place!



[topic_controls]
[/topic_controls]