Difference between revisions of "TexturePackFont.new"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
=== Description ===
 
=== Description ===
Creates a new [[TexturePackFont]] object.
+
Creates a new '''TexturePackFont''' object.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
TexturePackFont.new(texturePack,mappings,scale,anchor)
 
TexturePackFont.new(texturePack,mappings,scale,anchor)
</source>
+
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
'''texturePack''': (TexturePack) The [[TexturePack]] object that will be wrapped in this font<br/>
+
'''texturePack''': (TexturePack) the TexturePack object that will be wrapped in this font<br/>
'''mappings''': (table) A character to filename map to assictae characters with TexturePack images<br/>
+
'''mappings''': (table) a character to filename map to associate characters with TexturePack images<br/>
'''scale''': (double) A scale factor to apply to the texture pack images (default = 1)<br/>
+
'''scale''': (double) a scale factor to apply to the texture pack images (default = 1)<br/>
'''anchor''': (double) Where the images should be laid relative to the text baseline (default = 1)<br/>
+
'''anchor''': (double) where the images should be laid relative to the text baseline (default = 1)<br/>
 +
 
 +
=== Example ===
 +
'''Try to simulate arabic letters'''
 +
<syntaxhighlight lang="lua">
 +
local tp = TexturePack.new({"fonts/ar_ba.png", "fonts/ar_ta.png", "fonts/ar_tha.png"}) -- path to png images
 +
local font = TexturePackFont.new(tp, {ba="fonts/ar_ba.png", ta="fonts/ar_ta.png", sa="fonts/ar_tha.png"}, 3, 0) -- tp, mappings, scale, anchory
 +
local tf = TextField.new(font, "bata")
 +
local tf2 = TextField.new(font, "taba sa")
 +
local tf3 = TextField.new(font, "sa")
 +
tf:setPosition(64*6, 64*1)
 +
tf2:setPosition(64*6, 64*2)
 +
tf3:setPosition(64*6, 64*3)
 +
stage:addChild(tf)
 +
stage:addChild(tf2)
 +
stage:addChild(tf3)
 +
</syntaxhighlight>
  
 
{{TexturePackFont}}
 
{{TexturePackFont}}

Latest revision as of 15:33, 13 July 2023

Available since: Gideros 2021.9
Class: TexturePackFont

Description

Creates a new TexturePackFont object.

TexturePackFont.new(texturePack,mappings,scale,anchor)

Parameters

texturePack: (TexturePack) the TexturePack object that will be wrapped in this font
mappings: (table) a character to filename map to associate characters with TexturePack images
scale: (double) a scale factor to apply to the texture pack images (default = 1)
anchor: (double) where the images should be laid relative to the text baseline (default = 1)

Example

Try to simulate arabic letters

local tp = TexturePack.new({"fonts/ar_ba.png", "fonts/ar_ta.png", "fonts/ar_tha.png"}) -- path to png images
local font = TexturePackFont.new(tp, {ba="fonts/ar_ba.png", ta="fonts/ar_ta.png", sa="fonts/ar_tha.png"}, 3, 0) -- tp, mappings, scale, anchory
local tf = TextField.new(font, "bata")
local tf2 = TextField.new(font, "taba sa")
local tf3 = TextField.new(font, "sa")
tf:setPosition(64*6, 64*1)
tf2:setPosition(64*6, 64*2)
tf3:setPosition(64*6, 64*3)
stage:addChild(tf)
stage:addChild(tf2)
stage:addChild(tf3)