love.textinput (简体中文)
函数
概要
love.textinput( text )
参数
string text
- UTF-8 文本
Returns
无返回
注释
在 Android 和 iOS 上,默认禁用 textinput;调用love.keyboard.setTextInput来启用它。
例子
记录并打印用户输入的文本。
function love.load()
text = "Type away! -- "
end
function love.textinput(t)
text = text .. t
end
function love.draw()
love.graphics.printf(text, 0, 0, love.graphics.getWidth())
end
打印用户输入的文字,并在按下退格键(backspace)时删除一个文字。
local utf8 = require("utf8")
function love.load()
text = "Type away! -- "
-- enable key repeat so backspace can be held down to trigger love.keypressed multiple times.
love.keyboard.setKeyRepeat(true)
end
function love.textinput(t)
text = text .. t
end
function love.keypressed(key)
if key == "backspace" then
-- get the byte offset to the last UTF-8 character in the string.
local byteoffset = utf8.offset(text, -1)
if byteoffset then
-- remove the last UTF-8 character.
-- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
text = string.sub(text, 1, byteoffset - 1)
end
end
end
function love.draw()
love.graphics.printf(text, 0, 0, love.graphics.getWidth())
end
其他相关
- love
- love.keypressed
- love.keyboard.setTextInput
- love.keyboard.hasTextInput
- utf8
- textinput vs keypressed
其他语言
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