Difference between revisions of "love.graphics.origin"

(Created page with "Resets the current coordinate transformation. This function is always used to reverse any previous calls to love.graphics.rotate, love.graphics.scale, [[love.graphics.sh...")
 
(Note about love.draw.)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{newin|[[0.9.0]]|090|type=function}}
 
Resets the current coordinate transformation.
 
Resets the current coordinate transformation.
  
This function is always used to reverse any previous calls to [[love.graphics.rotate]], [[love.graphics.scale]], [[love.graphics.shear]] or [[love.graphics.translate]]. It returns the current transformation state to its defaults.
+
This function is always used to reverse any previous calls to [[love.graphics.rotate]], [[love.graphics.scale]], [[love.graphics.shear]] or [[love.graphics.translate]]. It restores the current transformation to its default state.
 +
 
 +
This function is called automatically right before [[love.draw]].
  
 
== Function ==
 
== Function ==
Line 15: Line 18:
 
== Example ==
 
== Example ==
 
<source lang="lua">
 
<source lang="lua">
 +
local image = love.graphics.newImage("path_to_your_image")
 
function love.draw()
 
function love.draw()
  love.graphics.push()  -- stores the coordinate system
+
love.graphics.push()  -- stores the coordinate system
    love.graphics.scale(0.5, 0.5)  -- reduce everything by 50% in both X and Y coordinates
+
love.graphics.scale(0.5, 0.5)  -- reduce everything by 50% in both X and Y coordinates
    love.graphics.print("Scaled text", 50, 50)  -- print half-sized text at 25x25
+
love.graphics.draw(image, 0, 0)  -- you can see a scaled image that you loaded on the left top of the screen.
    love.graphics.push()
+
love.graphics.print("Scaled text", 50, 50)  -- print half-sized text at 25x25
      love.graphics.origin()  -- Rest the state to the defaults.
+
love.graphics.draw(image, 0, 0) 
      love.graphics.draw(image) -- Draw the image on screen as if nothing was scaled.
+
love.graphics.push()
    love.graphics.pop()  -- return to our scaled coordinate state.
+
love.graphics.origin()  -- Reset the state to the defaults.
    love.graphics.print("Scaled text", 100, 100)  -- print half-sized text at 50x50
+
love.graphics.draw(image, 0, 0) -- Draw the image on screen as if nothing was scaled.
  love.graphics.pop()  -- return to the previous stored coordinated
+
love.graphics.pop()  -- return to our scaled coordinate state.
  love.graphics.print("Normal text", 50, 50)
+
love.graphics.print("Scaled text", 100, 100)  -- print half-sized text at 50x50
 +
love.graphics.pop()  -- return to the previous stored coordinated
 +
love.graphics.print("Normal text", 50, 50)
 
end
 
end
 
</source>
 
</source>
Line 40: Line 46:
 
{{#set:Description=Resets the current coordinate transformation.}}
 
{{#set:Description=Resets the current coordinate transformation.}}
 
{{#set:Sub-Category=Coordinate System}}
 
{{#set:Sub-Category=Coordinate System}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.origin}}
 
{{i18n|love.graphics.origin}}

Latest revision as of 18:30, 3 June 2022

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

Resets the current coordinate transformation.

This function is always used to reverse any previous calls to love.graphics.rotate, love.graphics.scale, love.graphics.shear or love.graphics.translate. It restores the current transformation to its default state.

This function is called automatically right before love.draw.

Function

Synopsis

love.graphics.origin()

Arguments

None

Returns

Nothing.

Example

local image = love.graphics.newImage("path_to_your_image")
function love.draw()
	love.graphics.push()   -- stores the coordinate system
		love.graphics.scale(0.5, 0.5)   -- reduce everything by 50% in both X and Y coordinates
		love.graphics.draw(image, 0, 0)  -- you can see a scaled image that you loaded on the left top of the screen.
		love.graphics.print("Scaled text", 50, 50)   -- print half-sized text at 25x25
		love.graphics.draw(image, 0, 0)  
			love.graphics.push()
			love.graphics.origin()  -- Reset the state to the defaults.
			love.graphics.draw(image, 0, 0) -- Draw the image on screen as if nothing was scaled.
		love.graphics.pop()   -- return to our scaled coordinate state.
		love.graphics.print("Scaled text", 100, 100)   -- print half-sized text at 50x50
	love.graphics.pop()   -- return to the previous stored coordinated
	love.graphics.print("Normal text", 50, 50)
end

See Also


Other Languages