Difference between revisions of "love.touch.getPosition"

(Created page)
 
m
 
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|userdata|id|The id value of the touch-press to get the position of. Use [[love.touch.getTouches]], [[love.touchpressed]], or [[love.touchmoved]] to obtain touch id values.}}
+
{{param|light userdata|id|The identifier of the touch-press. Use [[love.touch.getTouches]], [[love.touchpressed]], or [[love.touchmoved]] to obtain touch id values.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|number|x|The position along the x-axis of the touch-press inside the window, in pixels.}}
 
{{param|number|x|The position along the x-axis of the touch-press inside the window, in pixels.}}
Line 15: Line 15:
 
== Notes ==
 
== Notes ==
 
The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch-press positions as normalized values in the range of [0, 1], whereas this API reports positions in pixels.
 
The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch-press positions as normalized values in the range of [0, 1], whereas this API reports positions in pixels.
 +
 +
== Examples ==
 +
=== Draw a circle at each location in the window where a touch press is active. ===
 +
<source lang="lua">
 +
 +
function love.draw()
 +
    local touches = love.touch.getTouches()
 +
 +
    for i, id in ipairs(touches) do
 +
        local x, y = love.touch.getPosition(id)
 +
        love.graphics.circle("fill", x, y, 20)
 +
    end
 +
end
 +
</source>
  
 
== See Also ==
 
== See Also ==
 
* [[parent::love.touch]]
 
* [[parent::love.touch]]
 +
* [[love.touch.getTouches]]
 +
* [[love.touchpressed]]
 +
* [[love.touchreleased]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Gets the current position of the specified touch-press.}}
 
{{#set:Description=Gets the current position of the specified touch-press.}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.touch.getPosition}}
 
{{i18n|love.touch.getPosition}}

Latest revision as of 18:22, 22 December 2015

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

Gets the current position of the specified touch-press, in pixels.

Function

Synopsis

x, y = love.touch.getPosition( id )

Arguments

light userdata id
The identifier of the touch-press. Use love.touch.getTouches, love.touchpressed, or love.touchmoved to obtain touch id values.

Returns

number x
The position along the x-axis of the touch-press inside the window, in pixels.
number y
The position along the y-axis of the touch-press inside the window, in pixels.

Notes

The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch-press positions as normalized values in the range of [0, 1], whereas this API reports positions in pixels.

Examples

Draw a circle at each location in the window where a touch press is active.

function love.draw()
    local touches = love.touch.getTouches()

    for i, id in ipairs(touches) do
        local x, y = love.touch.getPosition(id)
        love.graphics.circle("fill", x, y, 20)
    end
end

See Also

Other Languages