Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java/Processing - Write my own pause method

  • 25-11-2011 5:17pm
    #1
    Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭


    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