Difference between revisions of "TexturePack"

From GiderosMobile
Line 14: Line 14:
 
<source lang="lua">
 
<source lang="lua">
 
local pack = TexturePack.new({"1.png", "2.png", "3.png", "4.png"})
 
local pack = TexturePack.new({"1.png", "2.png", "3.png", "4.png"})
 +
</source>
 +
 +
Example
 +
<source lang="lua">
 +
local tp = TexturePack.new({"gfx/2_2.png", "gfx/button01.png", "gfx/button02.png", "gfx/cat.jpg"})
 +
local bmp = Bitmap.new(tp:getTextureRegion("gfx/button01.png"))
 +
stage:addChild(bmp)
 
</source>
 
</source>
  

Revision as of 00:57, 6 June 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: TextureBase

Description

The TexturePack class specifies a texture pack (or texture atlas). A texture atlas is a large image which contains many smaller sub-images.

Gideros supports dynamic creation of texture atlases and pre-packed texture atlasses by using "Gideros Texture Packer" tool.

Dynamic Creation of Texture Packs

To create a texture pack dynamically (at run-time), create a TexturePack object with a table of file names of textures.

local pack = TexturePack.new({"1.png", "2.png", "3.png", "4.png"})

Example

local tp = TexturePack.new({"gfx/2_2.png", "gfx/button01.png", "gfx/button02.png", "gfx/cat.jpg"})
local bmp = Bitmap.new(tp:getTextureRegion("gfx/button01.png"))
stage:addChild(bmp)

Static Creation of Texture Packs

To create a pre-packed texture atlas, use "Gideros Texture Packer" tool:

Texture packer.png

This tool exports two files: a .txt file that specifies the positions of texture regions and a .png file of packed texture.

Use these two files to create a texture pack:

local pack = TexturePack.new("pack.txt", "pack.png")

Methods

TexturePack.new creates a new TexturePack object from textures
TexturePack.new creates a new TexturePack object from texture pack files
TexturePack.loadAsync asynchronously loads a TexturePack object from texture pack files

TexturePack:getLocation returns the location of the given texture in this pack
TexturePack:getRegionsNames returns all the region names of this pack
TexturePack:getTextureRegion returns the texture region for the given texture name

Events

Constants