Fixed step

Anything libgdx related goes here!

Fixed step

Postby xpdt » Wed Sep 12, 2018 5:03 pm

Hi
Is it possible to implement FixedStep frame rate like "FixedStepEngine" in AndEngine.
I need to run my game 60 fps in all devices.
I searched Google very much, but none of the solutions worked for me.
xpdt
 
Posts: 16
Joined: Mon Jul 04, 2016 2:29 am

Re: Fixed step

Postby evilentity » Wed Sep 12, 2018 5:42 pm

Which part didnt work, exactly? Fixed step is a fairly simple concept, run step while theres enough time in accumulator. Just what the FixedStepEngine does.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4427
Joined: Wed Aug 24, 2011 11:37 am

Re: Fixed step

Postby xpdt » Wed Sep 12, 2018 8:02 pm

FixedStepEngine in AndEngine works with NanoSecond:

Code: Select all
   @Override
   public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException {
      this.mSecondsElapsedAccumulator += pNanosecondsElapsed;

      final long stepLength = this.mStepLength;
      while (this.mSecondsElapsedAccumulator >= stepLength) {
         super.onUpdate(stepLength);
         this.mSecondsElapsedAccumulator -= stepLength;
      }
   }


I tried to use this method in libGDX:
Code: Select all
   public static final long NANOSECONDS_PER_SECOND = 1000 * 1000 * 1000;
        private long mStepLength = NANOSECONDS_PER_SECOND / 60;

   @Override
   public void render (float delta) {
      long d = (long) (delta * NANOSECONDS_PER_SECOND);
      this.mSecondsElapsedAccumulator += d;

      final long stepLength = this.mStepLength;
      while (this.mSecondsElapsedAccumulator >= stepLength) {
        super.render(delta);
        stage.act(delta);
        stage.draw();
         this.mSecondsElapsedAccumulator -= stepLength;
      }
   }
xpdt
 
Posts: 16
Joined: Mon Jul 04, 2016 2:29 am

Re: Fixed step

Postby evilentity » Wed Sep 12, 2018 9:06 pm

You are passing in actual delta instead of fixed step, so it doesnt make a whole lot of sense, does it now? You can use floats, you wont get more precision from by multiplying stuff. Drawing multiple times per frame wont do you any good either.
Code: Select all
private final float fixedStep = 1 / 60f;
private float accumulator = 0;
   @Override
   public void render (float delta) {
      accumulator += delta;

      while (accumulator >= fixedStep) {
        // this should not actually render stuff...
        super.render(fixedStep);
        stage.act(fixedStep);
        accumulator -= fixedStep ;
      }
       stage.draw();
   }

Now your problem is interpolation for rendering
Looking for a freelancer? PM me!
evilentity
 
Posts: 4427
Joined: Wed Aug 24, 2011 11:37 am

Re: Fixed step

Postby xpdt » Thu Sep 13, 2018 5:36 am

Ok, Works well. Thanks so much. :)
xpdt
 
Posts: 16
Joined: Mon Jul 04, 2016 2:29 am


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest