Skip to content

Instantly share code, notes, and snippets.

@nadar71
Forked from dantes2023/main.lua
Last active August 29, 2015 14:16
Show Gist options
  • Save nadar71/4741d6cf71f0f4eed9ef to your computer and use it in GitHub Desktop.
Save nadar71/4741d6cf71f0f4eed9ef to your computer and use it in GitHub Desktop.
local bg = display.newImage("images/bg.png")
bg.x = _W/2; bg.y = _H/2;
local car = display.newImage("images/car.png")
car.x = _W/2
car.y = _H - 250
car.name = "car"
-- understood proprierties of bezier curve
--local curve = bezier:curve({xInitial, xControlPoint1, xControlPoint2, xControlPoint3}, {yInitial, yControlPoint1, yControlPoint2, yControlPoint3})
local curve = bezier:curve({150, 1100, 150},{ 1080, 686, 500})
local x1, y1 = curve(10.51)
local line3 = display.newLine(x1, y1, x1+1, y1+1)
line3:setColor(0, 0, 255, 255 )
line3.width = 3
for i=0.02, 1.01, 0.01 do
local x, y = curve(i)
line3:append(x, y)
print(i, x, y)
end
-- move ball along curve
local pointInc = 0.00
local function follow (event )
if pointInc < 1.01 then
car.x, car.y = curve(pointInc)
--print(pointInc,ball.x, ball.y)
pointInc = pointInc + 0.01
else
Runtime:removeEventListener("enterFrame",follow)
end
end
Runtime:addEventListener("enterFrame",follow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment