Difference between revisions of "love.wheelmoved"
(Created page) |
m |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 8: | Line 8: | ||
=== Arguments === | === Arguments === | ||
{{param|number|x|Amount of horizontal mouse wheel movement. Positive values indicate movement to the right.}} | {{param|number|x|Amount of horizontal mouse wheel movement. Positive values indicate movement to the right.}} | ||
− | {{param|number|y|Amount of vertical mouse wheel movement. Positive values indicate | + | {{param|number|y|Amount of vertical mouse wheel movement. Positive values indicate upward movement.}} |
+ | |||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
Line 17: | Line 18: | ||
function love.wheelmoved(x, y) | function love.wheelmoved(x, y) | ||
if y > 0 then | if y > 0 then | ||
− | text = "Mouse wheel moved | + | text = "Mouse wheel moved up" |
elseif y < 0 then | elseif y < 0 then | ||
− | text = "Mouse wheel moved | + | text = "Mouse wheel moved down" |
end | end | ||
end | end | ||
Line 27: | Line 28: | ||
end | end | ||
</source> | </source> | ||
+ | |||
+ | |||
+ | === Smooth scrolling === | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | posx, posy = love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5 | ||
+ | velx, vely = 0, 0 -- The scroll velocity | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.rectangle( 'line', posx, posy, 50, 50 ) | ||
+ | end | ||
+ | |||
+ | function love.update( dt ) | ||
+ | posx = posx + velx * dt | ||
+ | posy = posy + vely * dt | ||
+ | |||
+ | -- Gradually reduce the velocity to create smooth scrolling effect. | ||
+ | velx = velx - velx * math.min( dt * 10, 1 ) | ||
+ | vely = vely - vely * math.min( dt * 10, 1 ) | ||
+ | end | ||
+ | |||
+ | function love.wheelmoved( dx, dy ) | ||
+ | velx = velx + dx * 20 | ||
+ | vely = vely + dy * 20 | ||
+ | end | ||
+ | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love]] | * [[parent::love]] | ||
[[Category:Callbacks]] | [[Category:Callbacks]] | ||
{{#set:Description=Callback function triggered when the mouse wheel is moved.}} | {{#set:Description=Callback function triggered when the mouse wheel is moved.}} | ||
− | {{#set:Subcategory= | + | {{#set:Subcategory=Mouse}} |
== Other Languages == | == Other Languages == | ||
{{i18n|love.wheelmoved}} | {{i18n|love.wheelmoved}} |
Latest revision as of 22:29, 7 March 2019
Available since LÖVE 0.10.0 |
This function is not supported in earlier versions. |
Callback function triggered when the mouse wheel is moved.
Contents
Function
Synopsis
love.wheelmoved( x, y )
Arguments
number x
- Amount of horizontal mouse wheel movement. Positive values indicate movement to the right.
number y
- Amount of vertical mouse wheel movement. Positive values indicate upward movement.
Returns
Nothing.
Examples
local text = ""
function love.wheelmoved(x, y)
if y > 0 then
text = "Mouse wheel moved up"
elseif y < 0 then
text = "Mouse wheel moved down"
end
end
function love.draw()
love.graphics.print(text, 10, 10)
end
Smooth scrolling
function love.load()
posx, posy = love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5
velx, vely = 0, 0 -- The scroll velocity
end
function love.draw()
love.graphics.rectangle( 'line', posx, posy, 50, 50 )
end
function love.update( dt )
posx = posx + velx * dt
posy = posy + vely * dt
-- Gradually reduce the velocity to create smooth scrolling effect.
velx = velx - velx * math.min( dt * 10, 1 )
vely = vely - vely * math.min( dt * 10, 1 )
end
function love.wheelmoved( dx, dy )
velx = velx + dx * 20
vely = vely + dy * 20
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info