Results 1 to 6 of 6
Thread: Does this function cause lag?
- 12-05-2009, 06:58 PM #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?
Its a function that rotates a picture and return a new rotated picture.PHP 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; }
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, 08:27 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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, 08:28 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Hehe, SMART!
(or im just stupid XD )
- 12-05-2009, 10:36 PM #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?
- 12-05-2009, 11:22 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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, 10:53 AM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 294
- Rep Power
- 0
Similar Threads
-
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
function
By nanna in forum New To JavaReplies: 1Last Post: 11-17-2008, 09:20 PM -
Need help with get function
By calicocal in forum New To JavaReplies: 10Last Post: 11-09-2008, 07:59 PM -
I want to add function
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:25 AM -
function name
By osval in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 08:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks