Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

more java questions =) [only 2]

Options
  • 19-05-2001 1:08am
    #1
    Registered Users Posts: 2,281 ✭✭✭


    1: is there a way or a class that can rotate an image by an angle (not just flip it)

    2:
    this is some code i have to make the player in my game rotate when a key is pressed (left/right arrow) - i want to make it mouse controlled like quake... it there a way to make the cursor dissapear into the game? i want to make it so that moveing mouse on the x axis rotates the player. (the rotation methods in class player are easy to change, and dont have to be boolean based)
    public void keyPressed(KeyEvent e){
        if (e.getKeyCode() == KeyEvent.VK_LEFT ){
            if (player != null)
            {
    	    player.setRotatingClockwise(true);
            }
        }
        if (e.getKeyCode() == KeyEvent.VK_RIGHT )
        {
            if (player != null)
            {
                player.setRotatingAnticlockwise(true);
            }
        }
    }
    

    - Dead Bank Clerk -
    Originally posted by Shinji:
    THIS IS THE THREAD THAT JUST ENDED.

    [This message has been edited by DeadBankClerk (edited 19-05-2001).]


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    1: Not that I know of. Your best bet is probably to use PixelGrabber to put the pixels in an array, then loop through each pixel and rotate it around the origin (in this case the center of the image) using basic 2d graphics (sin,cos etc), and then make a new image out of the rotated pixels with createImage(MemoryImageSource). There are some problems with this (like empty pixels after a 45º rotation - make sure the image is big enough to accomodate this), but I'm sure you can figure it out wink.gif
    Otherwise, you could just draw 8 or 16 (or 32 if you want is really smooth) images for the player faced in each direction, and use these instead of rotating the image itself. Might be faster at runtime, although it means more resources to be downloaded on initialization.

    2: Component.setCursor(Cursor) rolleyes.gif
    Rotating with the mouse isn't a problem - just record the x position of the cursor every frame, and compare it to the previous frame.


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    nice 1 jazz.

    you are always there when i need you most smile.gif


  • Closed Accounts Posts: 286 ✭✭Kev


    1) look up Graphics2D and AffineTransform on www.java.sun.com

    Mr. Chuffy


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    i making an applet :/

    so no java 2 for me :/


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    I found this a good read, might help you in what your doing.

    http://gpp.netfirms.com/algorithms/algorith.txt


  • Advertisement
Advertisement