Other notes:
- I am setting booleans for movement on my keybindings(using pressed and released)
- I am updating the image position in my update() functions using above boolean.
- I have a JPanel added to the main JApplet which I am drawing to by overridding the paintComponent method on(which i hate btw, wish i could add it to the main game loop and always call it instead along with getting key inputs)
[source lang="java"]public void run() { int frameCount = 0; //Used for time Calendar date; date = Calendar.getInstance(); //Get the latest instance of date int oldSecond = date.get(Calendar.MILLISECOND); //Get the current second. int timeLeft = 0;//We delay this time after we've updated to the framerate target. while(running){ date = Calendar.getInstance(); //Update Second if(date.get(Calendar.MILLISECOND) < oldSecond + 1000) //if a second has passed. { if(frameCount != TARGET_FRAMERATE) //Limit target frame rate. { frameCount++; Update(); }else{ //Get the time left in milliseconds timeLeft = (oldSecond + 1000) - date.get(Calendar.MILLISECOND); try { fps = frameCount; //Get frames per second. Thread.sleep(timeLeft); //and sleep the game thread for that amount of time. frameCount = 0; //Reset frame count. oldSecond = date.get(Calendar.SECOND); //Reset old second. } catch (InterruptedException e) { e.printStackTrace(); } } } } }[/source]
Edited by AlysiumX, 02 July 2012 - 05:32 PM.








