• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Optimization and fps on java for android

kewlkevkev

Lurker
Oct 20, 2013
4
3
I have recently followed and completed this tutorial . I am now trying to make my own application based on the guidance of the tutorial. The tutorial sets up a package with classes for framework, framework implementation, and then the actual game code. With two images being used as a scrolling background my game stutters every couple of seconds. I couldn't find anything in the tutorial about controlling fps. My question is would setting a max fps fix my problem and if so could someone show me an example of what it should look like. I apologize if this is a stupid question this is my first attempt at making an application in java and I have no formal instruction.
 
I'm not sure I understand what you mean, is the game running too slow or too fast?

If it's too fast, have something like this in the main game loop thread:

Code:
long prevTime = System.nanoTime();
while(running)
{[INDENT]
// get elapsed time since last frame
long currentTime = System.nanoTime();
float deltaTime = (currentTime - prevTime) * 0.000000001f;
prevTime = currentTime;
if (deltaTime > 0.25f) deltaTime = 0.25f; // cap a frame update to a quarter of a second

// update scene with deltaTime then render scene[/INDENT]}

deltaTime will hold the amount of time it passed since last frame, in seconds, in this case.


However, if the game updates too slow, then there could be a lot of reasons for it and I can't help if I have no idea what your actual code looks like. Just make sure you don't load the images from file every frame because that's extremely slow and inefficient, load them once at startup, and store them in memory in a Bitmap instead.


EDIT: by the way, I'm new here but why if you click on the button supposed to add [CODE] tags to your post it adds [HIGH] ? I see it confuses a lot of people.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones