Difference between revisions of "love.graphics.push"
m (Added love.graphics.shear to the list of related functions.) |
m |
||
(14 intermediate revisions by 8 users not shown) | |||
Line 4: | Line 4: | ||
== Function == | == Function == | ||
+ | Pushes the graphics state to the stack. | ||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
− | love.graphics.push() | + | love.graphics.push( stack ) |
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
− | + | {{New feature|0.9.2| | |
+ | {{param|StackType|stack ("transform")|The type of stack to push (e.g. just transformation state, or all love.graphics state).}} | ||
+ | |092}} | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | |||
== Examples == | == Examples == | ||
+ | Modify and restore the coordinate system. | ||
<source lang="lua"> | <source lang="lua"> | ||
function love.draw() | function love.draw() | ||
Line 23: | Line 28: | ||
end | end | ||
</source> | </source> | ||
+ | ---- | ||
+ | {{newin|[[0.9.2]]|092|type=example}} | ||
+ | Modify love.graphics state in a function, and restore it easily so other code isn't disturbed. | ||
+ | <source lang="lua"> | ||
+ | function DrawCoolThing() | ||
+ | love.graphics.push("all") -- save all love.graphics state so any changes can be restored | ||
+ | |||
+ | love.graphics.setColor(0, 0, 1) | ||
+ | love.graphics.setBlendMode("subtract") | ||
+ | |||
+ | love.graphics.circle("fill", 400, 300, 80) | ||
+ | |||
+ | love.graphics.pop() -- restore the saved love.graphics state | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.setColor(1, 0.5, 0.5) | ||
+ | love.graphics.circle("fill", 400, 300, 100) | ||
+ | |||
+ | DrawCoolThing() | ||
+ | |||
+ | love.graphics.rectangle("fill", 600, 200, 200, 200) -- still uses the color set at the top of love.draw | ||
+ | end | ||
+ | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love.graphics]] | * [[parent::love.graphics]] | ||
Line 30: | Line 60: | ||
* [[love.graphics.scale]] | * [[love.graphics.scale]] | ||
* [[love.graphics.shear]] | * [[love.graphics.shear]] | ||
+ | * [[love.graphics.origin]] | ||
+ | * [[StackType]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
{{#set:Description=Copies and pushes the current coordinate transformation to the transformation stack.}} | {{#set:Description=Copies and pushes the current coordinate transformation to the transformation stack.}} | ||
{{#set:Since=000}} | {{#set:Since=000}} | ||
+ | {{#set:Sub-Category=Coordinate System}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.graphics.push}} | {{i18n|love.graphics.push}} |
Latest revision as of 03:02, 21 October 2022
Copies and pushes the current coordinate transformation to the transformation stack.
This function is always used to prepare for a corresponding pop operation later. It stores the current coordinate transformation state into the transformation stack and keeps it active. Later changes to the transformation can be undone by using the pop operation, which returns the coordinate transform to the state it was in before calling push.
Function
Pushes the graphics state to the stack.
Synopsis
love.graphics.push( stack )
Arguments
StackType stack ("transform")
- The type of stack to push (e.g. just transformation state, or all love.graphics state).
Returns
Nothing.
Examples
Modify and restore the coordinate system.
function love.draw()
love.graphics.push() -- stores the default coordinate system
love.graphics.translate(...) -- move the camera position
love.graphics.scale(...) -- zoom the camera
-- use the new coordinate system to draw the viewed scene
love.graphics.pop() -- return to the default coordinates
-- draw the status display using the screen coordinates
end
Available since LÖVE 0.9.2 |
This example is not supported in earlier versions. |
Modify love.graphics state in a function, and restore it easily so other code isn't disturbed.
function DrawCoolThing()
love.graphics.push("all") -- save all love.graphics state so any changes can be restored
love.graphics.setColor(0, 0, 1)
love.graphics.setBlendMode("subtract")
love.graphics.circle("fill", 400, 300, 80)
love.graphics.pop() -- restore the saved love.graphics state
end
function love.draw()
love.graphics.setColor(1, 0.5, 0.5)
love.graphics.circle("fill", 400, 300, 100)
DrawCoolThing()
love.graphics.rectangle("fill", 600, 200, 200, 200) -- still uses the color set at the top of love.draw
end
See Also
- love.graphics
- love.graphics.pop
- love.graphics.translate
- love.graphics.rotate
- love.graphics.scale
- love.graphics.shear
- love.graphics.origin
- StackType
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