Difference between revisions of "love.mousepressed"

m (Examples: clarification)
(Updated for 0.10.0.)
Line 1: Line 1:
 
Callback function triggered when a mouse button is pressed.
 
Callback function triggered when a mouse button is pressed.
 
== Function ==
 
== Function ==
 +
{{newin|[[0.10.0]]|100|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.mousepressed( x, y, button, istouch )
 +
</source>
 +
=== Arguments ===
 +
{{param|number|x|Mouse x position, in pixels.}}
 +
{{param|number|y|Mouse y position, in pixels.}}
 +
{{param|number|button|The button index that was pressed. 1 is the primary button (usually left-click), 2 is the secondary button, etc.}}
 +
{{param|boolean|istouch|True if the mouse button press originated from a touchscreen touch-press.}}
 +
=== Returns ===
 +
Nothing.
 +
== Function ==
 +
{{oldin|[[0.10.0]]|100|type=variant}}
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 12: Line 26:
 
Nothing.
 
Nothing.
 
== Examples ==
 
== Examples ==
Position a string ("Text") wherever the user left-clicks.
+
Position a string ("Text") wherever the user left-clicks (version [[0.10.0]].)
 +
<source lang="lua">
 +
function love.load()
 +
  printx = 0
 +
  printy = 0
 +
end
 +
 
 +
function love.draw()
 +
  love.graphics.print("Text", printx, printy)
 +
end
 +
 
 +
function love.mousepressed(x, y, button, istouch)
 +
  if button == 1 then -- the primary button
 +
      printx = x
 +
      printy = y
 +
  end
 +
end
 +
</source>
 +
----
 +
Position a string ("Text") wherever the user left-clicks (version [[0.9.2]] and older.)
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
Line 18: Line 51:
 
   printy = 0
 
   printy = 0
 
end
 
end
 +
 
function love.draw()
 
function love.draw()
 
   love.graphics.print("Text", printx, printy)
 
   love.graphics.print("Text", printx, printy)
 
end
 
end
 +
 
function love.mousepressed(x, y, button)
 
function love.mousepressed(x, y, button)
 
   if button == "l" then -- this is the lowercase letter L, not a one (1)
 
   if button == "l" then -- this is the lowercase letter L, not a one (1)

Revision as of 01:39, 17 December 2015

Callback function triggered when a mouse button is pressed.

Function

Available since LÖVE 0.10.0
This variant is not supported in earlier versions.

Synopsis

love.mousepressed( x, y, button, istouch )

Arguments

number x
Mouse x position, in pixels.
number y
Mouse y position, in pixels.
number button
The button index that was pressed. 1 is the primary button (usually left-click), 2 is the secondary button, etc.
boolean istouch
True if the mouse button press originated from a touchscreen touch-press.

Returns

Nothing.

Function

Removed in LÖVE 0.10.0
This variant is not supported in that and later versions.

Synopsis

love.mousepressed( x, y, button )

Arguments

number x
Mouse x position.
number y
Mouse y position.
MouseConstant button
Mouse button pressed.

Returns

Nothing.

Examples

Position a string ("Text") wherever the user left-clicks (version 0.10.0.)

function love.load()
   printx = 0
   printy = 0
end

function love.draw()
   love.graphics.print("Text", printx, printy)
end

function love.mousepressed(x, y, button, istouch)
   if button == 1 then -- the primary button
      printx = x
      printy = y
   end
end

Position a string ("Text") wherever the user left-clicks (version 0.9.2 and older.)

function love.load()
   printx = 0
   printy = 0
end

function love.draw()
   love.graphics.print("Text", printx, printy)
end

function love.mousepressed(x, y, button)
   if button == "l" then -- this is the lowercase letter L, not a one (1)
      printx = x
      printy = y
   end
end

See Also


Other Languages