Slow 2D Tile Engine

If the game is running at 60 FPS you are displaying as many frames as the screen can show. Increasing the FPS of the game further is out of the question, as it will increase the speed of everything in the game PLUS making the game require better hardware to run. What you want to do to achieve faster movement is just to increase the movement speed of the player, right? I haven’t been able to figure out how you actually move the player (e.g. update it’s coordinates based on input, TL;DR it all you know…) so I can’t tell you exactly how to do it in your code, but you should do movement like this:

if(upKeyDown){
    player.y -= delta * moveSpeed;
}
//Very similar code for all the other directions
  • player.y is the current position of the player (you’ll probably not write it exactly like this (public access), but whatever)
  • moveSpeed is a variable that decides the speed of movement (DR. OBVIOUS TO THE RESCUE).
  • delta is the time since the last update, which should be calculated universally for all objects in the game in the game loop.

I think you should add delta calculation to your game loop:

        long time = System.currentTimeMillis();
        while (!endGame)
        {
            do
            {
                do
                {
                    try
                    {   
                        long currentTime = System.currentTimeMillis();
                        /*Delta = time passed since last update. Also, cast to int, as I doubt that delta will ever exceed Integer.MAX_VALUE... xD*/
                        int delta = (int)(currentTime - time); 
                        time = currentTime;
                        update(delta); //Update the game based on how long time has passed.
                        render();
                    }
                    catch (Exception ex) 
                    { 
                        System.err.println("Game Update Error: " + ex);
                    }
                     
                    try
                    {
                        Thread.sleep(rest);
                    }
                    catch (Exception ex)
                    {
                        System.out.println("Can't sleep!");
                    }
                } while (buffer.contentsRestored());
                 
                buffer.show();
                 
            } while (buffer.contentsLost());
        }

All your update methods should take an int delta parameter, and use it to determine how far to move things each update. Doing it like this also makes sure that the game runs at the same speed, regardless of how fast the computer running the game is. Even though the game only runs at 30FPS for example, the objects would make double as long “jumps” each update so they will move the same distance in the same time.
I hope things have cleared up a bit. xD

theagentd,

Thank you very much… that’s been the problem all along, and I was unable to pinpoint it. It now makes sense… the player’s been moving at the slowest possible speed this whole time. The delta method also makes perfect sense now with that illustrated example. I’ll get to work updating everything and trying to tie it all together. I appreciate your help and your examples; you’ve been very helpful.

Kind regards,
Colton

No problem. Those who ask questions are the ones that learn the most. ::slight_smile:

Lol yes, indeed. I know I have a crap ton to learn. Before this, I was just doing highly simple, static-screen based games like Pong. But I implemented a rough version of what you just explained to me, not everything yet but the most important parts, and it works wonderfully, just like I wanted it to. Thanks so much! I’m sure you’ll have plenty of questions to answer from me on the forums in the future (;]) and I know I can come here for help from now on without a problem.

Colton

Yeah, well, I’m not going anywhere. xp

Thank goodness… you’re the man! ;D