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

(Returns)
(Examples)
Line 32: Line 32:
 
<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>

Revision as of 15:28, 17 September 2015

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 current transformation to the transformation stack.

函数本体

love.graphics.push( )

参数

无参数

返回值

无返回值

Function

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

Pushes a specific type of state to the stack.

Synopsis

love.graphics.push( stack )

Arguments

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.

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