Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Is there a way to guarantee text size on all devices?
Started by ammar71 Jun 06 2019 11:39 AM

11 replies to this topic
hud text size font

Best Answer Rob Miracle , 12 June 2019 - 02:23 PM

zoomStretch is probably our most evil option. zoomStetch warps your screen items. You won't have any circles, they will all be ovals. Since text is created after the fact, It's probably still based on one pixel dimension and isn't considering the stretching. Note the numbers are not changed with regards to their shape.

 

Letterbox takes more work, no doubt, but it's the right way. This blog will help you understand the work needed to go letter box. Filling the space isn't difficult.

 

https://coronalabs.com/blog/2018/08/08/understanding-content-scaling-in-corona/

 

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

Hi all,

 

I am trying to add a HUD with coins at the top. The HUD will have an image of a coin with a text next to it containing the amount. (similar to https://i.pinimg.com/474x/6a/f9/32/6af9324d35a946f23687e8993c6e2700.jpg)

 

If I use the native font and work out the correct size on the simulator, would this work on ALL devices or do I need to use image digits to represent the number of coins in order to guarantee the size?

 

Thanks.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,586 posts
  • Corona SDK

Hi. Your question is unclear.

Explain what you mean for text to be the correct size.

Explain what it means to be incorrect.

Do you simply mean you want the text to retain the same relative size compared to the badge it overlays? If so, that should not automatically handled by scaling.

Note: I would NOT use a (default) system font. I would use font explicitly supplied (by you) in a TTF file.

[TOPIC: post.html]
#3

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

Appologies if the question is not clear.

 

To clarify:

I am going to have a PNG file that has a coin and a frame around it. I am going to position the PNG file at the top of the display. Then I am going to put a text on top of it. I want the text to always be within that frame.

 

If I use a TTF font as suggested, and if (say size 12) of that font works in the simulator and fits in the frame, am I guaranteed that the text will be in the frame on all devices?

In other words, will all the devices render a given font/size in the same way in relation to other graphics?

 

In the past in an other engine (Construct 2) I used a bitmap font to achieve this, but if a standard text can be used instead then that is much better.



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,904 posts
  • Enterprise

Using native.systemFont* will get you the device's default font and there is differences across devices because the fonts will be different.

 

display.newText() with a the same provided font "should" give you the same size, however, that API depends on the operating system's font rendering to generate the image used by display.newText() can create variances in spacing between lines in multiline text or spacing between words. But for your usage it should be very close.

 

Rob


  • Lava Level likes this

[TOPIC: post.html]
#5

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

I tried using a font as follows:

local diamond_frame = display.newImageRect(sceneGroup, "graphics/diamond_frame.png", 200, 46 )
diamond_frame.x = display.contentCenterX
diamond_frame.y = 80

num_of_diamonds = display.newText(sceneGroup, "123", diamond_frame.x+55, diamond_frame.y+5, 150, 42, "tuffy.ttf", 46)

But on the simulator I got:

font_size_problem.png

 

What am I doing wrong and how do I fix this please?



[TOPIC: post.html]
#6

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 826 posts
  • Corona SDK

The font might be doing alright, but there's something wrong with your scaling of the diamond frame. I'd suggest looking into your config.lua file. You should also check if you do some scaling to the diamond frame.



[TOPIC: post.html]
#7

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

@XeduR

 

My scaling is

scale = "zoomStretch",

 

Shouldn't that apply to both the frame and the text?



[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 826 posts
  • Corona SDK

Read through the scaling methods at https://docs.coronalabs.com/guide/basics/configSettings/index.html#scale

 

"zoomStretch" — scales the content area to fill the entire screen on any device, ignoring the content aspect ratio. This mode should be used with caution since it will stretch/warp images and text if the device's aspect ratio doesn't exactly match the content area's aspect ratio.

I personally use "letterbox" pretty much everywhere. I don't think you will be able to get display objects to align nicely across different displays with zoomStretch.



[TOPIC: post.html]
#9

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

Thanks @XeduR

Changing it t o letterbox helps but it leaves a part of the screen unused  :(

 

In my app, the aspect ration change with zoomStretch doesn't affect the app much except for this frame/text issue.

I thought it should apply the stretch to both text and frame equally. If it doesn't then the only option would be to use a spritesheet with the digits 0-9 and write a function that converts a number to sprites for display. This of course would increase the complexity of the code and would require sprite tracking for memory management.



[TOPIC: post.html]
#10

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 826 posts
  • Corona SDK

Deciding on the scaling method should really be one of the first things you do when starting out developing a game on Corona. Changing it later on in the project may take a lot of work.

One thing you could do is use bitmap fonts, but I'm not really sure if you can position them accurately with zoomStretch if the scaling distorts the diamond frame. There's probably some formula to figure out for offsetting images based on the amount of distortion, but I don't use that particular mode and I don't want to figure it out :P



[TOPIC: post.html]
#11

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,904 posts
  • Enterprise

  Best Answer

zoomStretch is probably our most evil option. zoomStetch warps your screen items. You won't have any circles, they will all be ovals. Since text is created after the fact, It's probably still based on one pixel dimension and isn't considering the stretching. Note the numbers are not changed with regards to their shape.

 

Letterbox takes more work, no doubt, but it's the right way. This blog will help you understand the work needed to go letter box. Filling the space isn't difficult.

 

https://coronalabs.com/blog/2018/08/08/understanding-content-scaling-in-corona/

 

Rob



[TOPIC: post.html]
#12

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 43 posts
  • Corona SDK

@XeduR & @Rob

 

Thanks. That was useful.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: hud, text size, font