Hi all!
How can I make my object follow random curve (from 1 to 3)?
So basically choose one curve to follow, and stick with it (not change curves)?
local bezier = require('bezier') local object= display.newImage("images/object.png") object.x = \_W/2 object.y = \_H - 250 object.name = "object" local curve1 = bezier:curve({150, 1100, 150},{ 1080, 686, 500}) local x1, y1 = curve1(10.51) local line1 = display.newLine(x1, y1, x1+1, y1+1) line1:setStrokeColor(0, 0, 1, 1) line1.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve1(i) line1:append(x, y) print(i, x, y) end local curve2 = bezier:curve({150, 1100, 150},{ 500, 200, 300}) local x2, y2 = curve2(10.51) local line2 = display.newLine(x2, y2, x2+1, y2+1) line2:setStrokeColor(0, 1, 0, 1) line2.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve2(i) line2:append(x, y) print(i, x, y) end local curve3 = bezier:curve({200, 900, 100},{ 1080, 686, 500}) local x3, y3 = curve3(10.51) local line3 = display.newLine(x3, y3, x3+1, y3+1) line3:setStrokeColor(1, 0, 1, 1) line3.strokeWidth = 3 for i=0.02, 1.01, 0.01 do local x, y = curve3(i) line3:append(x, y) print(i, x, y) end -- move object along curve local pointInc = 0.00 local function follow\_curve (event ) if pointInc \< 1.01 then object.x, object.y = curve1(pointInc) -- print(pointInc,object.x, object.y) pointInc = pointInc + 0.01 else Runtime:removeEventListener("enterFrame",follow\_curve) end end Runtime:addEventListener("enterFrame",follow\_curve);
In above code I follow curve No. 1, but how to follow random curve?
I tryed to conctatenate “curve” … x (where x is a math.random(1, 3)) but this does not work…
Tnx.
Gogi