Difference between revisions of "love.mouse.setPosition"

(Add an example, see also)
Line 10: Line 10:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
== 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]].
 +
<source lang="lua">
 +
function love.keypressed(key)
 +
  if tonumber(key) then  -- if the key is numeric (0-9), execute the next line
 +
  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
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::love.mouse]]
 
* [[parent::love.mouse]]
 +
* [[love.mouse.getPosition]]
 +
* [[love.mouse.getX]]
 +
* [[love.mouse.getY]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Sets the current position of the mouse.}}
 
{{#set:Description=Sets the current position of the mouse.}}

Revision as of 16:18, 27 September 2011

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 a new X position when the user presses a number key. The Y position is unchanged thanks to love.mouse.getY.

function love.keypressed(key)
   if tonumber(key) then   -- if the key is numeric (0-9), execute the next line
	  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

See Also


Other Languages