O'Reilly logo

Cinder – Begin Creative Coding by Krisjanis Rijnieks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding animation

As we already know, in each frame before we draw something, we use black color to clear everything that is left there from the previous frame. We use gl::clear() to do that. To create the effect of moving something, we need to change the object's position in each frame.

To do that, we will need to replace the values of the drawSolidCircle position parameters to variables. Let's declare a new variable that will hold the position of the circle on the screen:

  void prepareSettings( Settings *settings );
  Vec2f currentPosition;
};

This variable will hold the x and y position of the circle that we are drawing inside the draw() method.

Now we will set the initial value of the variable in the setup() method:

void BasicAnimationApp::setup() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required