Results 1 to 6 of 6
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default 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){
            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?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Hehe, SMART!
    (or im just stupid XD )

  4. #4
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Yeap =(
    Apparently that is whats causing the lag..
    Any better way of rotating pictures?

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

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

    Default

    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..

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 04:08 PM
  2. function
    By nanna in forum New To Java
    Replies: 1
    Last Post: 11-17-2008, 10:20 PM
  3. Need help with get function
    By calicocal in forum New To Java
    Replies: 10
    Last Post: 11-09-2008, 08:59 PM
  4. I want to add function
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:25 AM
  5. function name
    By osval in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 09:56 PM

Posting Permissions

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