Rotate image by x degrees? - Java -


this question has answer here:

all right, attempting create simple-ish game , have galaxy swirly id rotate, thing though, unsure how, if use graphics2d "g.rotate(x)" on screen had drawn spins want galaxy rotate , not words , stuff.

background class:

package tilemap;  import java.awt.graphics; import java.awt.graphics2d; import java.awt.image.bufferedimage;  import javax.imageio.imageio;  public class background {      private bufferedimage image;     private int x;     private int y;     private int dx;     private int dy;      public background(string imglctn){          try{             image = imageio.read(getclass().getresourceasstream(imglctn));          }         catch(exception e){             e.printstacktrace();         }     }        public void draw(graphics2d g){          g.drawimage(image, x - 44, y - 33, null);      } } 

the mainmenu class:

package gamestate;  import java.awt.color; import java.awt.font; import java.awt.graphics2d; import java.awt.event.keyevent;  import main.gamepanel; import tilemap.background;  public class mainmenu extends gamestate {      private int currentchoice = 0;      private background bg;      private string[] options = {              "start",             "options",             "quit"      };      private color titlecolor;     private font titlefont;     private font subfont;      public mainmenu(gamestatemanager gsm){          this.gsm = gsm;          try{             bg = new background("/backgrounds/menubg.png");              titlecolor = new color(0, 255, 0);             titlefont = new font("youre gone", font.italic, 30);             subfont = new font("youre gone", font.plain, 18);          }         catch(exception e){             e.printstacktrace();         }      }       @override     public void init() {      }      @override     public void update() {      }      @override     public void draw(graphics2d g) {          bg.draw(g);          g.setcolor(titlecolor);         g.setfont(titlefont);         g.drawstring("on way mars", gamepanel.width1 / 8, gamepanel.height1 / 3);         g.fillrect(gamepanel.width1 / 8, gamepanel.height1 / 3, (int) (gamepanel.width1/1.53), 3);           for(int = 0;i < options.length;i++){              g.setfont(subfont);              if(i == currentchoice){                 g.setcolor(new color(255,0,255));              }             else{                 g.setcolor(new color(0,255,255));             }             if(i < 1){                 g.drawstring(options[i], gamepanel.width1 / 8, gamepanel.height1 / 2 + i);             }             else{                 g.drawstring(options[i], gamepanel.width1 / 8, (gamepanel.height1 - 2) /2 + (i*20));             }         }      }     private void select(){          if(currentchoice == 0){          }         if(currentchoice == 1){          }         if(currentchoice == 2){              system.exit(0);          }      }      public void keypressed(int k){         if(k == keyevent.vk_w){             system.exit(0);         }     }     } 

i'm not expert myself might help: java: rotating images

here's answer:

`// required drawing location int drawlocationx = 300; int drawlocationy = 300;  // rotation information  double rotationrequired = math.toradian(45); double locationx = image.getwidth() / 2; double locationy = image.getheight() / 2; affinetransform tx = affinetransform.getrotateinstance(rotationrequired, locationx, locationy); affinetransformop op = new affinetransformop(tx, affinetransformop.type_bilinear);  // drawing rotated image @ required drawing locations g2d.drawimage(op.filter(image, null), drawlocationx, drawlocationy, null); 

please note i'm not taking credit original posters code!!!


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -