My failed attempt. Currently, I get the error: error: [string “-- tween.lua…”]:130: attempt to index a nil value (local ‘initial’)
I took some look at other questions asked (i searched tween mesh) but… ahh, I didn’t really understand. Well, they set the vertices directly. Whereas I’m going more for an approach where I want to make a function that would do, like, mesh:setRect, but it would be mesh:tweenRect… anyway, im giving up and going to bed, since its late. Hopefully this is my last question for a while, im feeling like i ask too much. Yes, thank you guys for always helping me
-- Meshtween
-- Use this function to perform your initial setu
local width, height = WIDTH/9, WIDTH/9*1.4
function setup()
print("Hello World!")
test = mesh()
for i = 1,4 do
test:addRect(WIDTH/9*i, HEIGHT/2, width/2, height/2)
test:setRectColor(i, 50*i, 200-i*50, 20*i)
end
end
-- works with meshes made entirely of rectangles
-- assumes the width, height are same
-- target should have keys x, y
function tween_rect(time, myMesh, index, target)
local position = myMesh:buffer('position')
local myTable = position:get()
local temp = mesh()
temp:addRect(target.x, target.y, width/2, height/2)
local target = temp:buffer('position')
local targTable = target:get()
table.move(targTable, 1, 6, 6 * index - 5)
local t1, t2, x,y,z, x2,y2,z2 = myTable, targTable
local sub, tar = {},{}
for i = index * 6 - 5, index * 6 do
x,y,z = t1[i].x, t1[i].y, t1[i].z --do x,y,z because tween wont work with vec3 object
x2,y2,z2 = t2[i].x, t2[1].y, t2[i].z
sub[i] = {x=x,y=y,z=z}
tar[i] = {x=x2,y=y2,z=z2}
tween(time, sub, tar)
t1[i] = vec3(sub[i].x, sub[i].y, sub[i].z)
--t2[i] = vec3(tar[i].x, tar[i].y, tar[i].z)
end
position:set(myTable)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
test:draw()
tween_rect(1, test, 1, {x=1000, y=700})
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
end