java - swing animation -


i have animation, , make disappear progressively when reaches left side of display area.

affinetransform @ = new affinetransform(); at.scale(-1, 1); at.translate((-clip.x + (clip.x - xpositiontopixel(imgx))), clip.y - 1); if ((clip.x - clip.width) < (at.gettranslatex() - bufimg.getwidth())) {   g2d.drawimage(bufimg, at, null); } else { @ = new affinetransform();                     at.scale(-1, 1);                     at.translate((-clip.x + (clip.x - xpositiontopixel(imgx))), clip.y - 1);                     g2d.drawimage(bufimg, (int)at.gettranslatex(), clip.y - 1, (int)(bufimg.getwidth() - (xpositiontopixel(imgx) + bufimg.getwidth())), clip.height, null); } 

i'm drawing animation right left, reason why scale , translate each coordinate. clip.x start of display area, , imgx new x coordinate.

thanks help.

i tried several way of achieving want , closest :

affinetransform @ = new affinetransform(); at.scale(-1, 1); at.translate((-clip.x + (clip.x - xpositiontopixel(imgx))), clip.y - 1);  if ((clip.x - clip.width) < (at.gettranslatex() - bufimg.getwidth())) {   g2d.drawimage(bufimg, at, null); } else {  @ = new affinetransform();                     at.scale(-1, 1);                     at.translate((-clip.x + (clip.x - xpositiontopixel(imgx))), clip.y - 1);                     g2d.drawimage(bufimg, (int)at.gettranslatex(), clip.y - 1, (int)(bufimg.getwidth() - (xpositiontopixel(imgx) + bufimg.getwidth())), clip.height, null); } 

but still not soluation has i'm shrinking width of image, still draw entirely.

still don't know problem (animation or transform?), here's simple snippet play with:

    final jbutton button = new jbutton("swinging!");     button.setsize(button.getpreferredsize());     button.dolayout();     final bufferedimage image = new bufferedimage(             button.getwidth(), button.getheight(), bufferedimage.type_int_rgb);     graphics2d g = image.creategraphics();     button.paint(g);     g.dispose();     final point location = new point(500, 100);     final jpanel panel = new jpanel() {         @override         protected void paintcomponent(graphics g) {             super.paintcomponent(g);             graphics2d gd = (graphics2d) g.create();             gd.translate(location.x, location.y);             gd.scale(-1, 1);             gd.drawimage(image, 0, 0, this);             gd.dispose();         }          @override         public dimension getpreferredsize() {             return new dimension(button.getwidth()* 10, button.getheight() * 20);         }       };     actionlistener l = new actionlistener() {          @override         public void actionperformed(actionevent e) {             location.x -= 5;             panel.repaint();             if (location.x < - button.getwidth()) {                 ((timer) e.getsource()).stop();             }         }     };     new timer(100, l).start(); 

Comments