Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Technique to handle fonts
Started by dodi_games Jul 09 2018 03:39 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 326 posts
  • Corona SDK

I'm beginning to understand a little more how to handle Corona's api and I wanted to ask if this would be a good technique to handle fonts. I'm on a phone so I do not going to use the <>

*****************************
--In main lua set a local variable to pass a font as a string
local font = "myFont.ttf"
composer.setVariable( font )
*****************************
--In scenes
local text1 = display.newText( "Font Test!", 100, 200, composer.getVariable(font), 16 )
*****************************
Or
*****************************
At the top of each scene module set a local variable to use "font"
local sceneFont = composer. getVariable( font)
--create
local text1 = display.newText( "Font Test!", 100, 200, sceneFont, 16 )

[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

I'd go with the second one.

Or this...
 

-- common.lua
local common = {}

common.font1 = "bubba.ttf"
common.font2 = "sue.ttf"

return common

At the top of each scene file
local common = require "common"

--create 
local text1 = display.newText( "Font Test!", 100, 200, common.font1, 16 ) 

  • dodi_games likes this

[TOPIC: post.html]
#3

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 326 posts
  • Corona SDK

thanks @roaminggamer!

 

In the common module can I add the sound in the same way? I only have one font and two sounds. My concern is how the memory and app performance is it going to behave when module it is no longer required? Lua takes care of it?




[topic_controls]
[/topic_controls]