TextureRegion: Difference between revisions
From GiderosMobile
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
'''<translate>Available since</translate>:''' Gideros 2011.6<br/> | '''<translate>Available since</translate>:''' Gideros 2011.6<br/> | ||
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/> | ||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
The [[Special:MyLanguage/TextureRegion|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. | |||
The [[Special:MyLanguage/TextureRegion|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. | |||
=== <translate>Examples</translate> === | === <translate>Examples</translate> === | ||
<source lang="lua"> | |||
<source lang="lua">local texture = Texture.new("atlas.png") | local texture = Texture.new("atlas.png") | ||
-- define 4 equal regions of size 100x100 from "atlas.png" | -- define 4 equal regions of size 100x100 from "atlas.png" | ||
| Line 29: | Line 28: | ||
stage:addChild(bitmap2) | stage:addChild(bitmap2) | ||
stage:addChild(bitmap3) | stage:addChild(bitmap3) | ||
stage:addChild(bitmap4)</source> | stage:addChild(bitmap4) | ||
</source> | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
| Line 38: | Line 39: | ||
[[Special:MyLanguage/TextureRegion:getScale|TextureRegion:getScale]] ''<translate>returns the scale ratio of the underlying atlas</translate>''<br/><!-- GIDEROSMTD:TextureRegion:getScale() returns the scale ratio of the underlying atlas --> | [[Special:MyLanguage/TextureRegion:getScale|TextureRegion:getScale]] ''<translate>returns the scale ratio of the underlying atlas</translate>''<br/><!-- GIDEROSMTD:TextureRegion:getScale() returns the scale ratio of the underlying atlas --> | ||
[[Special:MyLanguage/TextureRegion:setRegion|TextureRegion:setRegion]] ''<translate>sets the coordinates of the region</translate>''<br/><!-- GIDEROSMTD:TextureRegion:setRegion(x,y,width,height) sets the coordinates of the region --> | [[Special:MyLanguage/TextureRegion:setRegion|TextureRegion:setRegion]] ''<translate>sets the coordinates of the region</translate>''<br/><!-- GIDEROSMTD:TextureRegion:setRegion(x,y,width,height) sets the coordinates of the region --> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} | ||
Revision as of 23:29, 9 December 2019
Supported platforms: ![]()
![]()
![]()
![]()
![]()
![]()
![]()
Available since: Gideros 2011.6
Inherits from: Object
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
local texture = Texture.new("atlas.png")
-- define 4 equal regions of size 100x100 from "atlas.png"
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)
MethodsTextureRegion.new creates a new TextureRegion object |
EventsConstants |