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

m
(Undo revision 28031 by Popolon (talk) - The default value for sy is the same value as sx, not 1.)
(Tag: Undo)
 
(6 intermediate revisions by 3 users not shown)
Line 13: Line 13:
 
一般偏移值都设置成物件高度和宽度的一半,以便让物件的中心处于(x, y)坐标处。
 
一般偏移值都设置成物件高度和宽度的一半,以便让物件的中心处于(x, y)坐标处。
 
== 方法 ==
 
== 方法 ==
{{newin|[[0.8.0]]|080|type=variant}}
 
 
=== 语法 ===
 
=== 语法 ===
 
<source lang="lua">
 
<source lang="lua">
Line 31: Line 30:
 
=== 返回 ===
 
=== 返回 ===
 
无。
 
无。
== 方法 ==
+
 
{{oldin|[[0.8.0]]|080|type=variant}}
+
== Function ==
=== 语法 ===
+
{{newin|[[0.9.0]]|090|type=variant|text=It has replaced [[love.graphics.drawq]]}}
 +
自0.9.0开始,love.graphics.drawq函数被合并到了love.graphics.draw,以下的用法用以替代love.graphics.drawq。
 +
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy)
+
love.graphics.draw( texture, quad, x, y, r, sx, sy, ox, oy, kx, ky )
 
</source>
 
</source>
=== 参数 ===
+
=== Arguments ===
{{param|Drawable|drawable|可绘制物。}}
+
{{param|Texture|texture|A [[Texture]] ([[Image]] or [[Canvas]]) to texture the [[Quad]] with.}}
{{param|number|x|欲绘制物件的x轴坐标。}}
+
{{param|Quad|quad|The Quad to draw on screen.}}
{{param|number|y|欲绘制物件的y轴坐标。}}
+
{{param|number|x|The position to draw the object (x-axis).}}
{{param|number|r (0)|旋转量(弧度)}}
+
{{param|number|y|The position to draw the object (y-axis).}}
{{param|number|sx (1)|缩放因子(x轴)。可以为负值。}}
+
{{param|number|r (0)|Orientation (radians).}}
{{param|number|sy (sx)|缩放因子(y轴)。可以为负值。}}
+
{{param|number|sx (1)|Scale factor (x-axis).}}
{{param|number|ox (0)|原始偏移量(x轴)(比如设置为20,则会让欲绘制的物件向左偏移20像素。)}}
+
{{param|number|sy (sx)|Scale factor (y-axis).}}
{{param|number|oy (0)|原始偏移量(y轴)(比如设置为20,则会让欲绘制的物件向下偏移20像素。)}}
+
{{param|number|ox (0)|Origin offset (x-axis).}}
=== 返回 ===
+
{{param|number|oy (0)|Origin offset (y-axis).}}
无。
+
{{param|number|kx (0)|Shearing factor (x-axis).}}
 +
{{param|number|ky (0)|Shearing factor (y-axis).}}
 +
=== Returns ===
 +
Nothing.
 +
 
 
== 示例 ==
 
== 示例 ==
 
=== 在坐标(100, 100)处绘制图像 (the [https://love2d.org/w/images/c/c3/Resource-HamsterBall.png Hamster Ball]) ===
 
=== 在坐标(100, 100)处绘制图像 (the [https://love2d.org/w/images/c/c3/Resource-HamsterBall.png Hamster Ball]) ===
Line 67: Line 72:
 
function love.draw()
 
function love.draw()
 
   love.graphics.draw(hamster, 100, 100, math.rad(90), 1, 1, width / 2, height / 2)
 
   love.graphics.draw(hamster, 100, 100, math.rad(90), 1, 1, width / 2, height / 2)
 +
end
 +
</source>
 +
----
 +
{{newin|[[0.9.0]]|090|type=functionality}}
 +
=== Draw the top half of an image (the [https://love2d.org/w/images/c/c3/Resource-HamsterBall.png Hamster Ball]) at 100 by 100 pixels. ===
 +
<source lang="lua">
 +
function love.load()
 +
  image = love.graphics.newImage("hamster.png")
 +
  quad = love.graphics.newQuad(0, 0, 128, 64, image:getWidth(), image:getHeight())
 +
end
 +
 +
function love.draw()
 +
love.graphics.draw(image, quad, 100, 100)
 
end
 
end
 
</source>
 
</source>
Line 73: Line 91:
 
* [[parent::love.graphics_(简体中文)]]
 
* [[parent::love.graphics_(简体中文)]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 +
[[Sub-Category::Drawing (简体中文)| ]]
 
{{#set:Description=Draws objects on screen.在屏幕上绘制物件。}}
 
{{#set:Description=Draws objects on screen.在屏幕上绘制物件。}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.draw}}
 
{{i18n|love.graphics.draw}}

Latest revision as of 05:20, 6 October 2022

在屏幕上绘制物件。可绘制的物件可以是被加载的图形loaded images,也可以是其他可绘制Drawable物,比如粒子系统Particle System

除了简单地绘制之外,draw()方法还可以旋转、缩放或平移物件(比如,让图形在指定坐标系里居中)。

love.graphics.draw()默认从左上角开始计算锚点。

你也可以给sx或sy赋一个负值,以让绘制物水平或者垂直翻转。

物件的左上角会被绘制在(x, y)坐标处;(ox, oy)决定了物件的偏移值,偏移的计算先于旋转和缩放;然后物件被缩放(sx, sy)倍;接下来是旋转r弧度。

The default ColorMode blends the current drawing color into the image, so you will often want to invoke love.graphics.setColorMode("replace") before drawing images, to ensure that the drawn image matches the source image file.

一般偏移值都设置成物件高度和宽度的一半,以便让物件的中心处于(x, y)坐标处。

方法

语法

love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy, kx, ky )

参数

Drawable drawable
可绘制物。
number x
欲绘制物件的x轴坐标。
number y
欲绘制物件的y轴坐标。
number r (0)
旋转量(弧度)。
number sx (1)
缩放因子(x轴)。可以为负值。
number sy (sx)
缩放因子(y轴)。可以为负值。
number ox (0)
原始偏移量(x轴)。(比如设置为20,则会让欲绘制的物件向左偏移20像素。)
number oy (0)
原始偏移量(y轴)。(比如设置为20,则会让欲绘制的物件向下偏移20像素。)
number kx (0)
平行形变因子(x轴)。
number ky (0)
平行形变因子(y轴)。

返回

无。

Function

Available since LÖVE 0.9.0
It has replaced love.graphics.drawq.

自0.9.0开始,love.graphics.drawq函数被合并到了love.graphics.draw,以下的用法用以替代love.graphics.drawq。

Synopsis

love.graphics.draw( texture, quad, x, y, r, sx, sy, ox, oy, kx, ky )

Arguments

Texture texture
A Texture (Image or Canvas) to texture the Quad with.
Quad quad
The Quad to draw on screen.
number x
The position to draw the object (x-axis).
number y
The position to draw the object (y-axis).
number r (0)
Orientation (radians).
number sx (1)
Scale factor (x-axis).
number sy (sx)
Scale factor (y-axis).
number ox (0)
Origin offset (x-axis).
number oy (0)
Origin offset (y-axis).
number kx (0)
Shearing factor (x-axis).
number ky (0)
Shearing factor (y-axis).

Returns

Nothing.

示例

在坐标(100, 100)处绘制图像 (the Hamster Ball)

function love.load()
   hamster = love.graphics.newImage("hamster.png")
end
function love.draw()
   love.graphics.draw(hamster, 100, 100)
end

在坐标(100, 100)处,从中心开始绘制图像 (the Hamster Ball) ,并旋转90度

function love.load()
   hamster = love.graphics.newImage("hamster.png")
   width = hamster:getWidth()
   height = hamster:getHeight()
end
function love.draw()
   love.graphics.draw(hamster, 100, 100, math.rad(90), 1, 1, width / 2, height / 2)
end

Available since LÖVE 0.9.0
This functionality is not supported in earlier versions.

Draw the top half of an image (the Hamster Ball) at 100 by 100 pixels.

function love.load()
   image = love.graphics.newImage("hamster.png")
   quad = love.graphics.newQuad(0, 0, 128, 64, image:getWidth(), image:getHeight())
end

function love.draw()
	love.graphics.draw(image, quad, 100, 100)
end

See Also


Other Languages