Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java/Processing - Write my own pause method

  • 25-11-2011 06:17PM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 8,000 ✭✭✭
    Something about sandwiches


    I've made a little game (using Processing) for meself that I'm having a problem with. It reads from a text file in the format "12345,3". There is a tonne of these value pairs. The first/left value is a millisecond value for when the action should be performed. The values are stored in an array, and on each loop are split by the comma into a temp array and processed.

    I have a millisecond counter that starts from when the game loads, and i store that value in a variable. If I start the game straight away and don't pause it, the game works perfect. The problem I'm having is that the counter continues to run when the game is paused and that cant be changed.

    I have a boolean which handles the state of the game, ie playing/paused.

    What I need to do is store the millisecond value from when its paused, and then calculate the millisecond value from whatever it is at resume time, minus the value at pause. This must also take into account when the game is first loaded.

    I've had a few attempts but can't seem to get it right. Here's the code. Any help appreciated.
    public void draw()
    {
      imageMode(CORNERS);
      image(bg,0,0,screenXsize,screenYsize);// Fake the background image
      if (gameInProgress)
      {
        currentTimerValue = millis(); // Update the timer with the current milliseconds
        for(int i=0 ; i<songNotes.length ; i++)
        {
         // Check to see if the note times falls between the current time, or since the last loop (difficult to match exact millisecond)
         if( songNotes[i].getStartTime() > previousTimerValue && songNotes[i].getStartTime() <=(currentTimerValue))
             notes.add(songNotes[i]);
        }
       
        noStroke();
        textFont(f,18);
        drawButtons();  //Draws coloured buttons relating to Button presses on the controller
        drawHighScoreBox(); // Draws high score box up top right
        drawLines();  // Draws the strings
        moveNotes();  // Moves the notes across from right to left
        //Now set the cutoff for oldest note to display
        previousTimerValue=currentTimerValue;  //Used everytime on the following loop
      }
      else
      {
        handlePause();
      }
    }
    


Advertisement