Hi,
I’m new to programming on Codea and apps in general. What is the best way to animate an object (such as an ellipse) in an arc like a parabola (in a parabolic motion)? I’ve searched around on the forums and online and I can’t seem to figure it out.
Thanks!
@Staples I’m not sure what you’re after, but is it something like this.
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
b=physics.body(CIRCLE,5)
b.x=50
b.y=50
b.gravityScale=0
show=true
end
function draw()
background(40, 40, 50)
fill(255)
if show then
text("tap screen",WIDTH/2,HEIGHT-100)
end
ellipse(b.x,b.y,10)
if b.y<0 then
restart()
end
end
function touched(t)
if t.state==BEGAN then
b.gravityScale=1
b.linearVelocity=vec2(300,500)
show=false
end
end
Yeah that’s perfect. I tried using a variable “thrust” like in the Lunar Lander tutorial, but it didn’t look as professional as this. Thanks!
@dave1707 How would you get this to animate upon loading? I’ve tried putting the code from function touched(t) in the draw() function and nothing happened. I’ve also tried having a separate function called animate() where a timer is set in the draw() function and the animate() function is called every 300 frames, but neither of those seem to work.
@Staples This animates upon loading.
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
b=physics.body(CIRCLE,5)
b.x=50
b.y=50
b.gravityScale=1
b.interpolate=true
b.linearVelocity=vec2(300,500)
show=false
end
function draw()
background(40, 40, 50)
fill(255)
if show then
text("tap screen",WIDTH/2,HEIGHT-100)
else
ellipse(b.x,b.y,10)
if b.y<0 then
b:destroy()
show=true
end
end
end
function touched(t)
if t.state==BEGAN then
restart()
end
end