Difference between revisions of "love.graphics.push (简体中文)"

(参数)
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Copies and pushes the current coordinate transformation to the transformation stack.
+
<code>love.graphics.push</code>的作用是保存当前的坐标体系并将其激活到可修改状态(英文直译:推动到转换栈),然后可以使用[[love.graphics.scale]]以及[[love.graphics.translate]]等函数修改当前的坐标体系至一个新的坐标体系,在这个新的坐标体系上绘制的物体会发生形态变化(如放大和缩小、翻转、平移等),当制作视角追踪(或称摄像机,camera)功能时这一功能尤为重要。
 +
需要提醒,当新坐标体系上的物体绘制结束后必须使用[[love.graphics.pop]]函数将保存修改状态下的坐标体系的绘制效果,并使坐标体系返回至修改前的默认状态。
 +
*请注意,push和pop必须配合使用,否则LÖVE将会报错。
  
This function is always used to prepare for a corresponding [[love.graphics.pop|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 current transformation to the transformation stack.
 
=== 函数本体 ===
 
 
<source lang="lua">
 
<source lang="lua">
 
love.graphics.push( )
 
love.graphics.push( )
Line 13: Line 13:
 
无参数
 
无参数
  
=== Returns ===
+
=== 返回值 ===
Nothing.
+
无返回值
  
== Function ==
+
== 函数介绍 ==
 
{{newin|[[0.9.2]]|092|type=variant}}
 
{{newin|[[0.9.2]]|092|type=variant}}
 
Pushes a specific type of state to the stack.
 
Pushes a specific type of state to the stack.
=== Synopsis ===
+
=== 简介 ===
 
<source lang="lua">
 
<source lang="lua">
 
love.graphics.push( stack )
 
love.graphics.push( stack )
 
</source>
 
</source>
=== Arguments ===
+
=== 参数 ===
 
{{param|StackType|stack|The type of stack to push (e.g. just transformation state, or all love.graphics state).}}
 
{{param|StackType|stack|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.
 
Modify and restore the coordinate system.
 
<source lang="lua">
 
<source lang="lua">
 
function love.draw()
 
function love.draw()
love.graphics.push() -- stores the default coordinate system
+
love.graphics.push() -- 储存默认的坐标体系
love.graphics.translate(...) -- move the camera position
+
love.graphics.translate(...) -- 移动摄像机的位置
love.graphics.scale(...) -- zoom the camera
+
love.graphics.scale(...) -- 放大(缩小)视角
-- use the new coordinate system to draw the viewed scene
+
-- 使用新的坐标体系去绘制被观察的物体
love.graphics.pop() -- return to the default coordinates
+
love.graphics.pop() -- 回到默认的坐标体系
-- draw the status display using the screen coordinates
+
-- 使用屏幕的坐标绘制状态显示
 
end
 
end
 
</source>
 
</source>
Line 66: Line 67:
  
 
== See Also ==
 
== See Also ==
* [[parent::love.graphics]]
+
* [[parent::love.graphics (简体中文)]]
 
* [[love.graphics.pop]]
 
* [[love.graphics.pop]]
 
* [[love.graphics.translate]]
 
* [[love.graphics.translate]]

Latest revision as of 03:24, 19 September 2015

love.graphics.push的作用是保存当前的坐标体系并将其激活到可修改状态(英文直译:推动到转换栈),然后可以使用love.graphics.scale以及love.graphics.translate等函数修改当前的坐标体系至一个新的坐标体系,在这个新的坐标体系上绘制的物体会发生形态变化(如放大和缩小、翻转、平移等),当制作视角追踪(或称摄像机,camera)功能时这一功能尤为重要。 需要提醒,当新坐标体系上的物体绘制结束后必须使用love.graphics.pop函数将保存修改状态下的坐标体系的绘制效果,并使坐标体系返回至修改前的默认状态。

  • 请注意,push和pop必须配合使用,否则LÖVE将会报错。

函数介绍

第一种用法,无参数,功能是将当前坐标体系激活至可修改状态。

简介

love.graphics.push( )

参数

无参数

返回值

无返回值

函数介绍

Available since LÖVE 0.9.2
This variant is not supported in earlier versions.

Pushes a specific type of state to the stack.

简介

love.graphics.push( stack )

参数

StackType stack
The type of stack to push (e.g. just transformation state, or all love.graphics state).

返回值

无返回值

示例

Modify and restore the coordinate system.

function love.draw()
	love.graphics.push() -- 储存默认的坐标体系
	love.graphics.translate(...) -- 移动摄像机的位置
	love.graphics.scale(...) -- 放大(缩小)视角
	-- 使用新的坐标体系去绘制被观察的物体
	love.graphics.pop() -- 回到默认的坐标体系
	-- 使用屏幕的坐标绘制状态显示
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, 255)
    love.graphics.setBlendMode("subtractive")

    love.graphics.circle("fill", 400, 300, 80)

    love.graphics.pop() -- restore the saved love.graphics state
end

function love.draw()
    love.graphics.setColor(255, 128, 128)
    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


Other Languages