Difference between revisions of "Sprite:getBounds"

From GiderosMobile
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 +
'''Class:''' [[Sprite]]<br/>
 +
 
=== Description ===
 
=== Description ===
<br />
+
Returns a rectangle (as x, y, width and height) that encloses the sprite as it appears in another sprite coordinate system.
Returns a rectangle (as x, y, width and height) that encloses the sprite as it appears in another sprite's coordinate system.<br />
+
<syntaxhighlight lang="lua">
<br />
+
(number), (number), (number), (number) = Sprite:getBounds(targetSprite,constrain)
<source lang="lua">
+
</syntaxhighlight>
(number), (number), (number), (number) = Sprite:getBounds(targetSprite)
+
 
</source>
 
 
=== Parameters ===
 
=== Parameters ===
'''targetSprite''': (Sprite) the sprite that defines the other coordinate system to transform <br/>
+
'''targetSprite''': (Sprite) the sprite that defines the other coordinate system to transform<br/>
 +
'''constrain''': (bool) constrains the bounds to the base sprite layout '''default = false'''<br/>
 +
 
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (number) x coordinate<br/>
 
'''Returns''' (number) x coordinate<br/>
Line 15: Line 18:
 
'''Returns''' (number) width of Sprite<br/>
 
'''Returns''' (number) width of Sprite<br/>
 
'''Returns''' (number) height of Sprite<br/>
 
'''Returns''' (number) height of Sprite<br/>
 +
 
=== Examples ===
 
=== Examples ===
'''Example'''<br/>
+
<syntaxhighlight lang="lua">
<source lang="lua">local x, y, width, height = sprite:getBounds(sprite) -- returns local (untransformed) bounds<br />
+
local x, y, width, height = sprite:getBounds(sprite) -- returns local (untransformed) bounds
local x, y, width, height = sprite:getBounds(stage) -- returns bounds as transformed to stage&#039;s coordinate system<br /></source>
+
local x, y, width, height = sprite:getBounds(stage) -- returns bounds as transformed to the stage coordinate system
 +
</syntaxhighlight>
 +
 
 +
{{Sprite}}

Latest revision as of 05:01, 18 November 2023

Available since: Gideros 2011.6
Class: Sprite

Description

Returns a rectangle (as x, y, width and height) that encloses the sprite as it appears in another sprite coordinate system.

(number), (number), (number), (number) = Sprite:getBounds(targetSprite,constrain)

Parameters

targetSprite: (Sprite) the sprite that defines the other coordinate system to transform
constrain: (bool) constrains the bounds to the base sprite layout default = false

Return values

Returns (number) x coordinate
Returns (number) y coordinate
Returns (number) width of Sprite
Returns (number) height of Sprite

Examples

local x, y, width, height = sprite:getBounds(sprite) -- returns local (untransformed) bounds
local x, y, width, height = sprite:getBounds(stage) -- returns bounds as transformed to the stage coordinate system