9.1 Methods without arguments or result

A plain method does exactly the same thing, every time you call it. When you think back the the class movingCircle, you might want to add a method to put the circle back in the middle of the screen:

 
class movingCircle { 
  Circle c; 
  Vec2 speed; 
 
5  void reset() { 
    c.pos = Vec2(0); 
  } 
} 
 
10// somewhere in your application 
movingCircle mc; 
mc.reset();  
15

In this example, the circle’s position will be set to zero when the reset() method is called. This method consists of three parts:

void
Indicates the method has no result. (More about results in a moment.)
reset
The name of the method. You can pick your own name, but of course the restrictions for variable names also apply here. (Some characters are not allowed, don’t start with a number, …)
()
End with a couple of braces. Later on, arguments will be put between them.

Exercise
Add the reset() method above to the previous exercise. In the Update() function of your program, replace the code to reset the circle’s position with your method.

Add a method draw() to the same class. This method will draw the circle with a certain color. Again, replace the code in your app with this method.