Difference between revisions of "TextureRegion"

From GiderosMobile
Line 3: Line 3:
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 
=== Description ===
 
=== Description ===
<br />
+
<translate><br />
The `TextureRegion` class specifies a texture and a rectangular region in it. It is used to define independent texture regions<br />
+
The [[[TextureRegion]]] class specifies a texture and a rectangular region in it. It is used to define independent texture regions<br />
 
within a texture atlas which is a large image, which contains many smaller sub-images.<br />
 
within a texture atlas which is a large image, which contains many smaller sub-images.<br />
<br />
+
<br /></translate>
 
=== Examples ===
 
=== Examples ===
 
'''Example'''<br/>
 
'''Example'''<br/>
<source lang="lua">local texture = Texture.new(&quot;atlas.png&quot;)<br />
+
<source lang="lua">local texture = Texture.new(&quot;atlas.png&quot;)
<br />
+
 
-- define 4 equal regions of size 100x100 from &quot;atlas.png&quot;<br />
+
-- define 4 equal regions of size 100x100 from &quot;atlas.png&quot;
local region1 = TextureRegion.new(texture, 0,  0,  100, 100)<br />
+
local region1 = TextureRegion.new(texture, 0,  0,  100, 100)
local region2 = TextureRegion.new(texture, 100, 0,  100, 100)<br />
+
local region2 = TextureRegion.new(texture, 100, 0,  100, 100)
local region3 = TextureRegion.new(texture, 100, 100, 100, 100)<br />
+
local region3 = TextureRegion.new(texture, 100, 100, 100, 100)
local region4 = TextureRegion.new(texture, 0,  100, 100, 100)<br />
+
local region4 = TextureRegion.new(texture, 0,  100, 100, 100)
<br />
+
 
-- add these regions to scene tree<br />
+
-- add these regions to scene tree
local bitmap1 = Bitmap.new(region1)<br />
+
local bitmap1 = Bitmap.new(region1)
local bitmap2 = Bitmap.new(region2)<br />
+
local bitmap2 = Bitmap.new(region2)
local bitmap3 = Bitmap.new(region3)<br />
+
local bitmap3 = Bitmap.new(region3)
local bitmap4 = Bitmap.new(region4)<br />
+
local bitmap4 = Bitmap.new(region4)
<br />
+
 
stage:addChild(bitmap1)<br />
+
stage:addChild(bitmap1)
stage:addChild(bitmap2)<br />
+
stage:addChild(bitmap2)
stage:addChild(bitmap3)<br />
+
stage:addChild(bitmap3)
 
stage:addChild(bitmap4)</source>
 
stage:addChild(bitmap4)</source>
 
{|-
 
{|-

Revision as of 13:32, 23 August 2018

Supported platforms: android, ios, mac, pc
Available since: Gideros 2011.6

Description


The [[[TextureRegion]]] class specifies a texture and a rectangular region in it. It is used to define independent texture regions
within a texture atlas which is a large image, which contains many smaller sub-images.

Examples

Example

local texture = Texture.new(&quot;atlas.png&quot;)

-- define 4 equal regions of size 100x100 from &quot;atlas.png&quot;
local region1 = TextureRegion.new(texture, 0,   0,   100, 100)
local region2 = TextureRegion.new(texture, 100, 0,   100, 100)
local region3 = TextureRegion.new(texture, 100, 100, 100, 100)
local region4 = TextureRegion.new(texture, 0,   100, 100, 100)

-- add these regions to scene tree
local bitmap1 = Bitmap.new(region1)
local bitmap2 = Bitmap.new(region2)
local bitmap3 = Bitmap.new(region3)
local bitmap4 = Bitmap.new(region4)

stage:addChild(bitmap1)
stage:addChild(bitmap2)
stage:addChild(bitmap3)
stage:addChild(bitmap4)

Methods

TextureRegion.new - creates a new TextureRegion object
TextureRegion.new -
TextureRegion:getRegion - returns the coordinates of the region
TextureRegion:getScale - returns the scale ratio of the underlying atlas
TextureRegion:setRegion - sets the coordinates of the region

Events

Constants