# Thread: Does this function cause lag?

1. Senior Member
Join Date
Aug 2009
Posts
294
Rep Power
0

## 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?
PHP Code:
```public static BufferedImage rotateImg(BufferedImage bufferedImage,double radians){
AffineTransform tx = new AffineTransform();
//tx.scale(scalex, scaley);
//tx.shear(shiftx, shifty);
//tx.translate(x, y);
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?

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15
Does this make lag?

You can tell by replacing the method with one that does nothing - or something very simple like increment a counter.

3. Senior Member
Join Date
Aug 2009
Posts
294
Rep Power
0
Hehe, SMART!
(or im just stupid XD )

4. Senior Member
Join Date
Aug 2009
Posts
294
Rep Power
0
Yeap =(
Apparently that is whats causing the lag..
Any better way of rotating pictures?

5. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15
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.

6. Senior Member
Join Date
Aug 2009
Posts
294
Rep Power
0
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..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•