# Does this function cause lag?

• 12-05-2009, 07:58 PM
Does this function cause lag?
Hai!
Im making a game, where ur a character, and you walk on this planet(2d).
And when u walk, the planet and everything rotates around it, so the character actually never moves, just the enorivoment.
But I got this problem.
Even tho my main loop is made with a timer that uses only 5 milisec as wait time, it updates like approx half a second.
Its making it all look laggy.

Im woundering if it is lag or not.
Could this function be causeing the lag?
Code:

```public static BufferedImage rotateImg(BufferedImage bufferedImage,double radians){         double radians2 = radians*Math.PI/180;         radians = (int)radians2;         AffineTransform tx = new AffineTransform();         //tx.scale(scalex, scaley);         //tx.shear(shiftx, shifty);         //tx.translate(x, y);         tx.rotate(radians2, bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);         AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);         bufferedImage = op.filter(bufferedImage, null);         return bufferedImage;     }```
Its a function that rotates a picture and return a new rotated picture.
When it all rotates, it uses this function for all images (2 so far) and it changes its position with a simple equation.

Does this make lag?
• 12-05-2009, 09:27 PM
pbrockway2
Quote:

Does this make lag?

You can tell by replacing the method with one that does nothing - or something very simple like increment a counter.
• 12-05-2009, 09:28 PM
Hehe, SMART!
(or im just stupid XD )
• 12-05-2009, 11:36 PM
Yeap =(
Apparently that is whats causing the lag..
Any better way of rotating pictures?
• 12-06-2009, 12:22 AM
pbrockway2
A better way to rotate them is not to rotate them.

filter() creates and returns a whole new buffered image each time the method is called. If the image (the scene) is not actually changing this seems a waste. Instead just apply the transform not to the image but to the graphics context when you actually paint the image.
• 12-06-2009, 11:53 AM
Well, the problem is that it has to rotate..
It's a game where the galaxy spins aorund you when you walk on a planet.
But I guess I'll have to use opengl for this :(
I dont even know open gl!

But i tried using graphics2d to rotate, but it lags the same, but gives worse qualety..