That didn't work for me, but the "love.text input" works perfectly for me, only I can't get the rectangle to keep the size of the text if it goes beyond two lines, this is the code that I have managed to build, replace the font which I am using just because of the "getfont"
Code: Select all
io.stdout:setvbuf("no")
local utf8 = require("utf8")
function love.load()
string = ""
font = love.graphics.getFont()
strw = font:getWidth(string)
strh = font:getHeight(string)
anchorectangulo = 0 + strw * 2
altorectangulo = 0 + strh * 2
love.keyboard.setKeyRepeat(true)
end
function love.textinput(t)
string = string .. t
end
function love.keypressed(key)
if key == "backspace" then
local byteoffset = utf8.offset(string, -1)
if byteoffset then
string = string.sub(string, 1, byteoffset - 1)
end
end
end
function love.update()
anchorectangulo = font:getWidth(string) + 10
altorectangulo = altorectangulo
if anchorectangulo > love.graphics.getWidth()/4 then
anchorectangulo = love.graphics.getWidth()/4 + 10
end
end
function love.draw()
love.graphics.setFont(font)
love.graphics.setColor(1, 1, 1, 0.2)
love.graphics.rectangle("fill", 0, 0, anchorectangulo , altorectangulo )
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(string, 0 + strw / 2, 0 + strh / 2,love.graphics.getWidth()/4)
end