durianodour

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About durianodour

  • Rank
    Newbie

Personal Information

  • Interests
    Audio
    Business
    Design
    DevOps
    Education
    Production
    Programming
    QA
  1. Hi, I am a newbie game developer. I need to develop a simple 2D game, it is really simple. I have a Human model that should jump every n seconds. 1. User sets different several options in settings. The first option is the game time and the second option is jump count. 2. The Game engine should determine how much time is required to model one single jump, simply by dividing gameTime/jumpCount. As a result we will find the time per one jump. 3. Single jump has some kind of physics. When the human model jumps, it should bend the elbow, knees. Jump starts from the bottommost point to some top point. Up and down. But this doesn't really important and all physics should be considered by moving some point up and down. I cannot figure out how should I build my game loop and physics processing to respect user options. If a device cannot draw or process physics at desired time it should be laggy, but the whole game time should as a user has set in settings. Please suggest a strategy to implement this correctly. Thanks
  2. Android The main game loop FPS independent

    Thanks everyone for answers. I have much simpler case. I don't need to have all these complex calculations depending on different forces currently acting on an object. I have a simple game. I have only one object a ball that is falling down, or a different shape. I need just to catch it or skip. So I guess I don't need to integrate and save states between frames. The only one variable that I change in my update method is mCenterX += (mVelocityVector.x * timeElapsed); mCenterY += (mVelocityVector.y * timeElapsed + gameSpeed.getValue()) These variables just represent the position of a falling shape and that is all. The reason I tried to apply described method, just to develop even a simple game following best practices. So maybe you could suggest me another way to achieve FPS independent rendering considering my requirements. I would be grateful for any further help
  3. I am just a newbie game developer, I am trying to create a frame independent game loop. I am currently using the following code private class MainGameThread extends Thread { public static final int PAUSE_SLEEP_TIME = 10; long previous = getCurrentTimeInMillis(); long totalElapsed = 0; long gameTimeStart = 0; long currentTime = getCurrentTimeInMillis(); long accumulatorTime = 0; @Override public void run() { gameTimeStart = getCurrentTimeInMillis(); while (mIsRunning) { // Pause game while (mIsPaused) { try { Thread.sleep(PAUSE_SLEEP_TIME); } catch (InterruptedException e) { e.printStackTrace(); } } long current = getCurrentTimeInMillis(); long elapsed = current - previous; previous = current; processGameInput(); updateGameState(elapsed); totalElapsed += elapsed; if (totalElapsed > MainGame.MS_PER_FRAME) { drawGame(); totalElapsed -= MainGame.MS_PER_FRAME; if (totalElapsed > MainGame.MS_PER_FRAME) { Log.e("GAME", "Performance warning, rendering or update took too long"); } } checkIfGameShouldStop(gameTimeStart); } shutdownGracefully(); } private void shutdownGracefully() { } } It works, how ever it performs differently on different devices In my game models update method I am performing the following actions mCenterX += (mVelocityVector.x * timeElapsed); mCenterY += (mVelocityVector.y * timeElapsed + gameSpeed.getValue()) I have read this article https://gafferongames.com/post/fix_your_timestep/ But I can't understand the final example double t = 0.0; double dt = 0.01; double currentTime = hires_time_in_seconds(); double accumulator = 0.0; State previous; State current; while ( !quit ) { double newTime = time(); double frameTime = newTime - currentTime; if ( frameTime > 0.25 ) frameTime = 0.25; currentTime = newTime; accumulator += frameTime; while ( accumulator >= dt ) { previousState = currentState; integrate( currentState, t, dt ); t += dt; accumulator -= dt; } const double alpha = accumulator / dt; State state = currentState * alpha + previousState * ( 1.0 - alpha ); render( state ); } What does the State class object mean in this case. Could someone please help to adapt this example to my case or explain the example from the article and how I could update my loop to be frame independent ? Thanks