Difference between revisions of "TexturePack:getRegionsNames"
From GiderosMobile
(Created page with "__NOTOC__ '''<translate>Available since</translate>:''' Gideros 2021.9<br/> '''<translate>Class</translate>:''' TexturePack<br/> === Descr...") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | '''Available since:''' Gideros 2021.9<br/> | |
− | ''' | + | '''Class:''' [[TexturePack]]<br/> |
− | ''' | ||
=== Description === | === Description === | ||
Returns a list of all texture names in this pack. | Returns a list of all texture names in this pack. | ||
− | < | + | <syntaxhighlight lang="lua"> |
(table) = TexturePack:getRegionsNames(texturename) | (table) = TexturePack:getRegionsNames(texturename) | ||
− | </ | + | </syntaxhighlight> |
=== Parameters === | === Parameters === | ||
− | '''texturename''': (string) < | + | '''texturename''': (string) texture path<br/> |
+ | |||
+ | === Return values === | ||
+ | '''Returns''' (table) list of texture names in this pack<br/> | ||
+ | |||
+ | === Example === | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | -- pack all the deco images (TexturePack) for perf | ||
+ | local bgtpt = {} -- background texture pack table | ||
+ | local bgtptx = {} -- background texture pack table x | ||
+ | local fgtpt = {} -- foreground texture pack table | ||
+ | local fgtptx = {} -- foreground texture pack table x | ||
+ | for i = 1, #tm.layers do | ||
+ | local layer = tm.layers[i] | ||
+ | if layer.name:match("bg_deco_images") then | ||
+ | if layer.name:sub(#layer.name) == "x" then | ||
+ | for i = 1, #layer.objects do | ||
+ | bgtptx[#bgtptx+1] = tilesetimages[layer.objects[i].gid].path | ||
+ | end | ||
+ | else | ||
+ | for i = 1, #layer.objects do | ||
+ | bgtpt[#bgtpt+1] = tilesetimages[layer.objects[i].gid].path | ||
+ | end | ||
+ | end | ||
+ | elseif layer.name:match("fg_deco_images") then | ||
+ | if layer.name:sub(#layer.name) == "x" then | ||
+ | for i = 1, #layer.objects do | ||
+ | fgtptx[#fgtptx+1] = tilesetimages[layer.objects[i].gid].path | ||
+ | end | ||
+ | else | ||
+ | for i = 1, #layer.objects do | ||
+ | fgtpt[#fgtpt+1] = tilesetimages[layer.objects[i].gid].path | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
− | === | + | local bgtp = TexturePack.new(bgtpt, nil, nil, { format=TextureBase.RGBA4444, } ) |
− | + | local bgtpx = TexturePack.new(bgtptx, nil, nil, { format=TextureBase.RGBA4444, } ) | |
+ | local fgtp = TexturePack.new(fgtpt, nil, nil, { format=TextureBase.RGBA4444, } ) | ||
+ | local fgtpx = TexturePack.new(fgtptx, nil, nil, { format=TextureBase.RGBA4444, } ) | ||
+ | if #bgtp:getRegionsNames() > 0 then print(bgtp:getSize()) end | ||
+ | if #bgtpx:getRegionsNames() > 0 then print(bgtpx:getSize()) end | ||
+ | if #fgtp:getRegionsNames() > 0 then print(fgtp:getSize()) end | ||
+ | if #fgtpx:getRegionsNames() > 0 then print(fgtpx:getSize()) end | ||
+ | </syntaxhighlight> | ||
{{TexturePack}} | {{TexturePack}} |
Latest revision as of 16:29, 12 July 2025
Available since: Gideros 2021.9
Class: TexturePack
Description
Returns a list of all texture names in this pack.
(table) = TexturePack:getRegionsNames(texturename)
Parameters
texturename: (string) texture path
Return values
Returns (table) list of texture names in this pack
Example
-- pack all the deco images (TexturePack) for perf
local bgtpt = {} -- background texture pack table
local bgtptx = {} -- background texture pack table x
local fgtpt = {} -- foreground texture pack table
local fgtptx = {} -- foreground texture pack table x
for i = 1, #tm.layers do
local layer = tm.layers[i]
if layer.name:match("bg_deco_images") then
if layer.name:sub(#layer.name) == "x" then
for i = 1, #layer.objects do
bgtptx[#bgtptx+1] = tilesetimages[layer.objects[i].gid].path
end
else
for i = 1, #layer.objects do
bgtpt[#bgtpt+1] = tilesetimages[layer.objects[i].gid].path
end
end
elseif layer.name:match("fg_deco_images") then
if layer.name:sub(#layer.name) == "x" then
for i = 1, #layer.objects do
fgtptx[#fgtptx+1] = tilesetimages[layer.objects[i].gid].path
end
else
for i = 1, #layer.objects do
fgtpt[#fgtpt+1] = tilesetimages[layer.objects[i].gid].path
end
end
end
end
local bgtp = TexturePack.new(bgtpt, nil, nil, { format=TextureBase.RGBA4444, } )
local bgtpx = TexturePack.new(bgtptx, nil, nil, { format=TextureBase.RGBA4444, } )
local fgtp = TexturePack.new(fgtpt, nil, nil, { format=TextureBase.RGBA4444, } )
local fgtpx = TexturePack.new(fgtptx, nil, nil, { format=TextureBase.RGBA4444, } )
if #bgtp:getRegionsNames() > 0 then print(bgtp:getSize()) end
if #bgtpx:getRegionsNames() > 0 then print(bgtpx:getSize()) end
if #fgtp:getRegionsNames() > 0 then print(fgtp:getSize()) end
if #fgtpx:getRegionsNames() > 0 then print(fgtpx:getSize()) end