Difference between revisions of "love.mouse.setPosition"

(Undo revision 12683 by Bangseongbeom (talk))
m (Shorten description.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Sets the current position of the mouse.
+
Sets the current position of the mouse. Non-integer values are floored.
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 11: Line 11:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
Snap the mouse to a new X position when the user presses a number key. The Y position is unchanged thanks to [[love.mouse.getY]].
+
Snap the mouse to the horizontal center of the screen while maintaining the coordinate along the y-axis by using [[love.mouse.getY]].
 
<source lang="lua">
 
<source lang="lua">
function love.keypressed(key)
+
function love.keypressed( )
  if tonumber(key) then   -- if the key is numeric (0-9), execute the next line
+
   love.mouse.setPosition( love.graphics.getWidth() * 0.5, love.mouse.getY() )
  love.mouse.setPosition(tonumber(key) * 10, love.mouse.getY())   -- multiply the key by 10 to make the effect more visible, maintain the Y position via getY
 
  end
 
 
end
 
end
 
</source>
 
</source>

Latest revision as of 09:34, 10 March 2017

Sets the current position of the mouse. Non-integer values are floored.

Function

Synopsis

love.mouse.setPosition( x, y )

Arguments

number x
The new position of the mouse along the x-axis.
number y
The new position of the mouse along the y-axis.

Returns

Nothing.

Examples

Snap the mouse to the horizontal center of the screen while maintaining the coordinate along the y-axis by using love.mouse.getY.

function love.keypressed( )
  love.mouse.setPosition( love.graphics.getWidth() * 0.5, love.mouse.getY() )
end

See Also


Other Languages