Difference between revisions of "love.mouse.setPosition"

(Undo revision 12683 by Bangseongbeom (talk))
(Simplify example)
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>

Revision as of 02:39, 16 October 2016

Sets the current position of the mouse.

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