Difference between revisions of "TexturePack:getRegionsNames"

From GiderosMobile
 
(2 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Returns a list of all texture names in this pack.
 
Returns a list of all texture names in this pack.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(table) = TexturePack:getRegionsNames(texturename)
 
(table) = TexturePack:getRegionsNames(texturename)
</source>
+
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
Line 14: Line 14:
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (table) list of texture names in this pack<br/>
 
'''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