Difference between revisions of "Global Command: getCursorPos"
From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 28: | Line 28: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Example 2: Counteracting the scroll position issue. (''example below require vs 4.1'') | ||
+ | <syntaxhighlight> | ||
+ | local pos = {} -- empty table | ||
+ | pos.x = game.ScrollPosition.x + getCursorPos().x -- absolute x position on entire scene | ||
+ | pos.y = game.ScrollPosition.y + getCursorPos().y -- absolute y position on entire scene | ||
+ | </syntaxhighlight> | ||
Revision as of 03:06, 19 November 2014
Function History |
---|
Available since v3.3 |
Stores the current position (absolute) of the mouse cursor into an x,y table, which can be used in a query to check if the current position is over an object/character or a certain part of the scene etc. Note: just noticed that it is actually returning coordinates based on current scroll position, as if: scroll position is always 0,0 instead of what it should be. You can counteract this by adding cursor position + scroll position together.
Syntax:
getCursorPos()
Example:
-- let's store the current position into a variable!
local curPos = getCursorPos()
-- let's check if the stored cursor position equals another x,y value!
if curPos.x == 200 and curPos.y == 400 then
-- do some action!
else
-- do some other action!
end
Example 2: Counteracting the scroll position issue. (example below require vs 4.1)
local pos = {} -- empty table
pos.x = game.ScrollPosition.x + getCursorPos().x -- absolute x position on entire scene
pos.y = game.ScrollPosition.y + getCursorPos().y -- absolute y position on entire scene
Arguments
none
Flags
none
Return
pos
Table containing x,y values of current mouse cursor position