TextureRegion: Difference between revisions
From GiderosMobile
No edit summary |
m Text replacement - "</source>" to "</syntaxhighlight>" |
||
| (19 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Supported platforms:''' android | <!-- GIDEROSOBJ:TextureRegion --> | ||
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> | |||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
'''Inherits from:''' [[Object]]<br/> | |||
=== Description === | === 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 (a large image which contains many smaller sub-images). | |||
The | |||
within a texture atlas | === Example === | ||
<syntaxhighlight lang="lua"> | |||
=== | 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) | |||
-- define 4 equal regions of size 100x100 from | local region2 = TextureRegion.new(texture, 100, 0, 100, 100) | ||
local region1 = TextureRegion.new(texture, 0, 0, 100, 100) | local region3 = TextureRegion.new(texture, 100, 100, 100, 100) | ||
local region2 = TextureRegion.new(texture, 100, 0, 100, 100) | local region4 = TextureRegion.new(texture, 0, 100, 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) | |||
-- add these regions to scene tree | local bitmap2 = Bitmap.new(region2) | ||
local bitmap1 = Bitmap.new(region1) | local bitmap3 = Bitmap.new(region3) | ||
local bitmap2 = Bitmap.new(region2) | local bitmap4 = Bitmap.new(region4) | ||
local bitmap3 = Bitmap.new(region3) | |||
local bitmap4 = Bitmap.new(region4) | stage:addChild(bitmap1) | ||
stage:addChild(bitmap2) | |||
stage:addChild(bitmap1) | stage:addChild(bitmap3) | ||
stage:addChild(bitmap2) | stage:addChild(bitmap4) | ||
stage:addChild(bitmap3) | </syntaxhighlight> | ||
stage:addChild(bitmap4)</ | |||
{|- | {|- | ||
| style="width: 50%;"| | | style="width: 50%; vertical-align:top;"| | ||
=== Methods === | === Methods === | ||
[[TextureRegion.new]] | [[TextureRegion.new]] ''creates a new TextureRegion object''<br/><!--GIDEROSMTD:TextureRegion.new(texture) creates a new TextureRegion object--> | ||
[[TextureRegion.new]] | [[TextureRegion.new]] <br/><!--GIDEROSMTD:TextureRegion.new(texture,x,y,width,height) --> | ||
[[TextureRegion:getRegion]] | [[TextureRegion:getRegion]] ''returns the coordinates of the region''<br/><!--GIDEROSMTD:TextureRegion:getRegion(baseCoordiniates) returns the coordinates of the region--> | ||
[[TextureRegion:getScale]] | [[TextureRegion:getScale]] ''returns the scale ratio of the underlying atlas''<br/><!--GIDEROSMTD:TextureRegion:getScale() returns the scale ratio of the underlying atlas--> | ||
[[TextureRegion:setRegion]] | [[TextureRegion:setRegion]] ''sets the coordinates of the region''<br/><!--GIDEROSMTD:TextureRegion:setRegion(x,y,width,height) sets the coordinates of the region--> | ||
| style="width: 50%;"| | |||
| style="width: 50%; vertical-align:top;"| | |||
=== Events === | === Events === | ||
=== Constants === | === Constants === | ||
|} | |} | ||
{{GIDEROS IMPORTANT LINKS}} | |||
Latest revision as of 13:33, 13 July 2023
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 (a large image which contains many smaller sub-images).
Example
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 |