Results 1 to 5 of 5
  1. #1
    Kasp3r is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default Java rotate(); problem

    Hello all, I'm started to study java and I have come to problem, I have tried to solve this few days but now I need to ask help.

    I'm trying to rotate 1 image but looks like I'm rotating all images.
    How can I rotate only 1 image to x degree. I have already made a function what counts that "kulma" to rad.

    Java Code:
       public void update( Graphics g ) {   
    backg.drawImage( bgimg, 0, 0, this ); 
    backg.drawImage( hp, 0,0, this);  
    backg.setColor( Color.white );  
    backg.drawImage( player, x2, y2, this );  backg.drawImage(meteor,cx,cy,this);  
    backg.drawString("Gas left:" +kaasu, 400,10); 
    
    backg.drawString("Kulma Deg: "+Math.atan(kulma) * 180/Math.PI , 200,25);  
    
    backg.drawString("Score:" +score, 300,10); 
    
    backg.drawString("Health: 100", 34,10); 
    
    backg.drawString("Mouse at:" +mx, 475,10); 
    
    backg.drawString(","+my, 550,10);  
    lol(g);   
    g.drawImage( backbuffer, 0, 0, this );          
    }     
    
    public void paint( Graphics g ) {        
    update( g );     
    }     
    
    public void lol( Graphics g ) {   
    Graphics2D g2d=(Graphics2D)g;    
    
    if (mx>x2) g2d.rotate(kulma *-1); 
    else g2d.rotate(kulma);     
    
    backg.drawImage( ase,x2, y2 +4, this );        
    }
    and if I do this:
    Java Code:
    g2d.rotate(kulma);
    backg.drawImage(ase,x,y,this);
    g2d.rotate(kulma *-1);
    And if I rotate the graphics back after drawing single image.
    nothing don't rotate because I use backg. to draw in buffer and not g2d.

    So what I need to do..?
    Sorry for my bad english and thanks for all upcoming help :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This code looks funny to me as it looks as if you're trying to do some drawing to a BufferedImage but doing this drawing from within the paint method and possibly losing benefits of using a background BufferedImage. I suggest you create a small compilable program that requires no outside resources other than perhaps images available online (I often use the public domain Java-Duke images located here: Duke Images), that we can compile and run unmodified on our computers at home, and that demonstrates your problem. For more details on what I'm asking for, please see my link on creating an SSCCE in my signature below.

    Much luck!

  3. #3
    Kasp3r is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    I can change those drawings like this:

    Java Code:
    public void paint(){
    
    backg.draw........
    }
    and call it in run loop or where ever..
    I just want to know how can I rotate only 1 image.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default

    Stubborn aren't you? You were asked for an SSCCE, not a couple of meaningless lines of code.

    Looks like you don't really want to learn anything.

    db

  5. #5
    Kasp3r is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    You mean:

    1)I should use to load images

    Java Code:
    try {
                 URL url = new URL(getCodeBase(), "strawberry.jpg");
                 img = ImageIO.read(url);
             } catch (IOException e) {
             }
    2) Paste the whole code here that you can help me and run it on your comp?

    3) I'm sorry if I were rude but I miss understood that SSCCE thing because of my bad english.

Similar Threads

  1. How to rotate an image
    By ChipChamp in forum New To Java
    Replies: 4
    Last Post: 06-20-2012, 07:22 PM
  2. How to rotate catalina.out without restarting tomcat
    By kzvi.kzvi.1 in forum Advanced Java
    Replies: 1
    Last Post: 03-25-2010, 06:05 PM
  3. Image rotate
    By Micromani in forum AWT / Swing
    Replies: 0
    Last Post: 03-17-2010, 01:33 PM
  4. Rotate Image!
    By Moncleared in forum AWT / Swing
    Replies: 1
    Last Post: 02-11-2009, 05:22 PM
  5. JFrame rotate
    By etheralthougt in forum AWT / Swing
    Replies: 1
    Last Post: 10-24-2008, 06:03 AM

Posting Permissions

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