Thursday 25 April 2019

Moving an image along a path

When you have to move an object along a path or do an animation, many programmers lose days or weeks to calculate the formula that mathematically describes the path or animation.

Livecode allows you to avoid this and simply do it by hand!

As an example, I'll show you how to make a ball bounce in less than a minute.

First draw the ball directly in Livecode, just press the oval button, make a circle and then indicate the colors of the gradients, to have something like this:
Let's call it "ball".
Then we create a path, which we will call "mypath", by pressing the freehand button and drawing the trajectory of the ball by hand, obtaining something similar to this:


Make invisible the path and then create a Start button with this code:

on mouseUp
   move graphic "ball" to the points of graphic "mypath" in 10 sec
end mouseUp

Pushing the butto this will be the result:

Just one line of code! (thank livecode)

No comments:

Post a Comment