Difference between revisions of "love.graphics.rotate"
m (add links to pop & push) |
(added an example: how to rotate around a point) |
||
Line 11: | Line 11: | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | == Examples == | ||
+ | === Rotating a static scene === | ||
+ | This example shows how to rotate a static scene around a given point. Since the rotation is always around the origin, translating the center of the screen to the origin and back around the rotate operation makes the effective rotation point be the center of the screen. This is demonstrated by drawing a rectangle that shows the rotation and a point that is right in the center and thus does not move when the scene rotates. Note that the drawing commands have coordinates that depend solely on the screen size. | ||
+ | <source lang="lua"> | ||
+ | local angle = 0 | ||
+ | |||
+ | function love.draw() | ||
+ | local width = love.graphics.getWidth() | ||
+ | local height = love.graphics.getHeight() | ||
+ | -- rotate around the center of the screen by angle radians | ||
+ | love.graphics.translate(width/2, height/2) | ||
+ | love.graphics.rotate(angle) | ||
+ | love.graphics.translate(-width/2, -height/2) | ||
+ | -- draw a white rectangle slightly off center | ||
+ | love.graphics.setColor(0xff, 0xff, 0xff) | ||
+ | love.graphics.rectangle('fill', width/2-100, height/2-100, 300, 400) | ||
+ | -- draw a five-pixel-wide blue point at the center | ||
+ | love.graphics.setPointSize(5) | ||
+ | love.graphics.setColor(0, 0, 0xff) | ||
+ | love.graphics.point(width/2, height/2) | ||
+ | end | ||
+ | |||
+ | function love.update(dt) | ||
+ | love.timer.sleep(10) | ||
+ | angle = angle + dt * math.pi/2 | ||
+ | angle = angle % (2*math.pi) | ||
+ | end | ||
+ | </source> | ||
== See Also == | == See Also == | ||
* [[parent::love.graphics]] | * [[parent::love.graphics]] |
Revision as of 08:42, 27 February 2010
Rotates the coordinate system in two dimensions.
Calling this function affects all future drawing operations by rotating the coordinate system around the origin by the given amount of radians. This change lasts until love.draw() exits.
Contents
Function
Synopsis
love.graphics.rotate( angle )
Arguments
number angle
- The amount to rotate the coordinate system in radians.
Returns
Nothing.
Examples
Rotating a static scene
This example shows how to rotate a static scene around a given point. Since the rotation is always around the origin, translating the center of the screen to the origin and back around the rotate operation makes the effective rotation point be the center of the screen. This is demonstrated by drawing a rectangle that shows the rotation and a point that is right in the center and thus does not move when the scene rotates. Note that the drawing commands have coordinates that depend solely on the screen size.
local angle = 0
function love.draw()
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
-- rotate around the center of the screen by angle radians
love.graphics.translate(width/2, height/2)
love.graphics.rotate(angle)
love.graphics.translate(-width/2, -height/2)
-- draw a white rectangle slightly off center
love.graphics.setColor(0xff, 0xff, 0xff)
love.graphics.rectangle('fill', width/2-100, height/2-100, 300, 400)
-- draw a five-pixel-wide blue point at the center
love.graphics.setPointSize(5)
love.graphics.setColor(0, 0, 0xff)
love.graphics.point(width/2, height/2)
end
function love.update(dt)
love.timer.sleep(10)
angle = angle + dt * math.pi/2
angle = angle % (2*math.pi)
end