How do i make a resart button for my game

edited May 2017 in How To...

Hi i really want to know how to make a restart button for my game i cant figure it out


  • edited May 2017

    you could say if(key=='n.......

    With mouse

    or place a text on the screen



    int restartX; 
    int restartY;

    before setup()

    then to click it with the mouse say

    if(mousePressed&&dist(mouseX,mouseY,restartX,restartY) <50) {


    to restart write a function restart() and call it, here clear your screen with background and reset variables eg typeOfBrush, used colors, size of ellipse etc.

    in general when you ask something, better show your code or describe what you mean

    Best, Chrisir ;-)

  • Could you post the code you've already got? That way it will be easier to help you. Here is an example where a ball gets reset with a click of a mousebutton:

    float x, y, xSpeed, ySpeed;
    void setup(){
    void ballSetup(){
      x = width/2;
      y = width/2;
      xSpeed = random(-1, 1);
      ySpeed = random(-1, 1);
    void draw(){
       x += xSpeed;
       y += ySpeed;
    void mousePressed(){

    The idea is that you have a function that holds the information of how the game should start. If it is run, it will change all the variables so that everything is how it is supposed to be at the start of the game.

  • That depends on the complexity of the game.
    For simple games, you just need to reset some variables to initial values. For more complex ones, you'll have to create new instances of all the objects used.

Sign In or Register to comment.