Difference between revisions of "love.focus"

m
m
 
(6 intermediate revisions by 4 users not shown)
Line 4: Line 4:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.focus(f)
+
love.focus( focus )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|boolean|f|Window focus}}
+
{{param|boolean|focus|True if the window gains focus, false if it loses focus. }}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 22: Line 22:
  
 
function love.focus(f)
 
function love.focus(f)
   if not f then
+
   if f then
     text = "UNFOCUSED!!"
+
     print("Window is focused.")
     print("LOST FOCUS")
+
     text = "FOCUSED"
 
   else
 
   else
     text = "FOCUSED!"
+
     print("Window is not focused.")
     print("GAINED FOCUS")
+
     text = "UNFOCUSED"
 
   end
 
   end
 
end
 
end
  
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love]]
 
* [[parent::love]]
 
[[Category:Callbacks]]
 
[[Category:Callbacks]]
 
{{#set:Description=Callback function triggered when window receives or loses focus.}}
 
{{#set:Description=Callback function triggered when window receives or loses focus.}}
 +
{{#set:Subcategory=Window}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.focus}}
 
{{i18n|love.focus}}

Latest revision as of 22:31, 7 March 2019

Available since LÖVE 0.7.0
This callback is not supported in earlier versions.

Callback function triggered when window receives or loses focus.

Function

Synopsis

love.focus( focus )

Arguments

boolean focus
True if the window gains focus, false if it loses focus.

Returns

Nothing.

Example

function love.load()
  text = "FOCUSED"
end

function love.draw()
  love.graphics.print(text,0,0)
end

function love.focus(f)
  if f then
    print("Window is focused.")
    text = "FOCUSED"
  else
    print("Window is not focused.")
    text = "UNFOCUSED"
  end
end

See Also


Other Languages