Hi! I try to make a code that stores in a table every touch on the screen (after i will make lines between them) to draw.
I used the touch function to draw the touches as in the example from the wiki but it does not change a variable, i want something like void f(&x,&y) from c++ but with touches which will be stored in a table.
Any idea? Feel free to say your opinion.
Touch to table
Re: Touch to table
Lua is all about tables. Put the touch events into a table and tinker from there...
Code: Select all
local touches = {}
function love.touchpressed(id, x, y, dx, dy, pressure)
local t = {
id = id,
x = x,
y = y,
dx = dx,
dy = dy,
p = pressure
}
table.insert(touches, t)
end
local lg = love.graphics
function love.draw()
for i, touch in ipairs(touches) do
lg.setColor(255,255,255)
lg.circle('fill', touch.x, touch.y, 25)
lg.setColor(0,0,0)
lg.printf(tostring(touch.id), touch.x-25, touch.y, 50, 'center')
end
end
Re: Touch to table
Keep in mind you can have multiple return values in Lua. The idiomatic thing to do would probably be x, y = f(), where f returns two values. Or you might prefer f(t) instead, where t is a table, and f sets t.x and t.y to some values.
Re: Touch to table
I tried it with get touches but yes, there many x and y and i could not apply it as a single variable.
Thank you a lot for the help!
Thank you a lot for the help!
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 5 guests