Difference between revisions of "Shape:getBoundingBox"
m |
m |
||
(10 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{oldin|[[0.8.0]]|080|type=function}} | ||
Gets the bounding box of the shape. | Gets the bounding box of the shape. | ||
This function can be used in a nested fashion with [[love.graphics.polygon]]. | This function can be used in a nested fashion with [[love.graphics.polygon]]. | ||
== Function == | == Function == | ||
=== Synopsis === | === Synopsis === | ||
− | + | A bounding box is the smallest rectangle that encapsulates the entire polygon. | |
<source lang="lua"> | <source lang="lua"> | ||
x1, y1, x2, y2, x3, y3, x4, y4 = Shape:getBoundingBox( ) | x1, y1, x2, y2, x3, y3, x4, y4 = Shape:getBoundingBox( ) | ||
</source> | </source> | ||
+ | Vertexes are returned starting from the bottom-left in a clockwise fashion (bottom-left, top-left, top-right, bottom-right). | ||
+ | |||
=== Arguments === | === Arguments === | ||
None. | None. | ||
=== Returns === | === Returns === | ||
− | {{param|number|x1|The x-component of the first vertex.}} | + | {{param|number|x1|The x-component of the first vertex, bottom-left.}} |
− | {{param|number|y1|The y-component of the first vertex.}} | + | {{param|number|y1|The y-component of the first vertex, bottom-left.}} |
− | {{param|number|x2|The x-component of the second vertex.}} | + | {{param|number|x2|The x-component of the second vertex, top-left.}} |
− | {{param|number|y2|The y-component of the second vertex.}} | + | {{param|number|y2|The y-component of the second vertex, top-left.}} |
− | {{param|number|x3|The x-component of the third vertex.}} | + | {{param|number|x3|The x-component of the third vertex, top-right.}} |
− | {{param|number|y3|The y-component of the third vertex.}} | + | {{param|number|y3|The y-component of the third vertex, top-right.}} |
− | {{param|number|x4|The x-component of the fourth vertex.}} | + | {{param|number|x4|The x-component of the fourth vertex, bottom-right.}} |
− | {{param|number|y4|The y-component of the fourth vertex.}} | + | {{param|number|y4|The y-component of the fourth vertex, bottom-right.}} |
+ | == Example == | ||
+ | |||
+ | [[FILE:Love Ex getBoundingBox.png|300px]] | ||
+ | |||
+ | |||
+ | :And here's the source code if you want to try/test/see it yourself. | ||
+ | |||
+ | <source lang="lua"> | ||
+ | |||
+ | |||
+ | function love.load() | ||
+ | |||
+ | world = love.physics.newWorld(650, 650) | ||
+ | world:setGravity(0,700) | ||
+ | world:setMeter(64) | ||
+ | |||
+ | body = love.physics.newBody(world, 650/2, 650/2, 0, 0) | ||
+ | shape = love.physics.newRectangleShape(body, 0, 0, 300, 300, 0) | ||
+ | |||
+ | |||
+ | love.graphics.setFont(18) | ||
+ | love.graphics.setBackgroundColor(255, 255, 255, 255) | ||
+ | love.graphics.setMode(650, 650, false, true, 0) | ||
+ | |||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | |||
+ | X1, Y1, X2, Y2, X3, Y3, X4, Y4 = shape:getBoundingBox() | ||
+ | |||
+ | love.graphics.setColor(0,0,0,255) | ||
+ | |||
+ | love.graphics.print("X1, Y1", X1, Y1) | ||
+ | love.graphics.print("X2, Y2", X2, Y2) | ||
+ | love.graphics.print("X3, Y3", X3, Y3) | ||
+ | love.graphics.print("X4, Y4", X4, Y4) | ||
+ | |||
+ | end | ||
+ | |||
+ | </source> | ||
+ | |||
+ | |||
== See Also == | == See Also == | ||
* [[parent::Shape]] | * [[parent::Shape]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description=Gets the bounding box of the shape. | + | {{#set:Description=Gets the bounding box of the shape.}} |
− | }} | + | {{#set:Since=000}} |
+ | == Other Languages == | ||
+ | {{i18n|Shape:getBoundingBox}} |
Latest revision as of 17:53, 29 May 2013
Removed in LÖVE 0.8.0 |
This function is not supported in that and later versions. |
Gets the bounding box of the shape. This function can be used in a nested fashion with love.graphics.polygon.
Function
Synopsis
A bounding box is the smallest rectangle that encapsulates the entire polygon.
x1, y1, x2, y2, x3, y3, x4, y4 = Shape:getBoundingBox( )
Vertexes are returned starting from the bottom-left in a clockwise fashion (bottom-left, top-left, top-right, bottom-right).
Arguments
None.
Returns
number x1
- The x-component of the first vertex, bottom-left.
number y1
- The y-component of the first vertex, bottom-left.
number x2
- The x-component of the second vertex, top-left.
number y2
- The y-component of the second vertex, top-left.
number x3
- The x-component of the third vertex, top-right.
number y3
- The y-component of the third vertex, top-right.
number x4
- The x-component of the fourth vertex, bottom-right.
number y4
- The y-component of the fourth vertex, bottom-right.
Example
- And here's the source code if you want to try/test/see it yourself.
function love.load()
world = love.physics.newWorld(650, 650)
world:setGravity(0,700)
world:setMeter(64)
body = love.physics.newBody(world, 650/2, 650/2, 0, 0)
shape = love.physics.newRectangleShape(body, 0, 0, 300, 300, 0)
love.graphics.setFont(18)
love.graphics.setBackgroundColor(255, 255, 255, 255)
love.graphics.setMode(650, 650, false, true, 0)
end
function love.draw()
X1, Y1, X2, Y2, X3, Y3, X4, Y4 = shape:getBoundingBox()
love.graphics.setColor(0,0,0,255)
love.graphics.print("X1, Y1", X1, Y1)
love.graphics.print("X2, Y2", X2, Y2)
love.graphics.print("X3, Y3", X3, Y3)
love.graphics.print("X4, Y4", X4, Y4)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info