tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
2
ZUGRIFFE
464
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Registriert seit
    Apr 2002
    Ort
    keine Angaben
    Beiträge
    578
    Hi,

    ist es möglich ein Image oder eine Zeichnung ohne Repaint eine andere Positon zuzuordnen? Ich würde gerne sowas wie ein Ball hüpfen lassen. Das blöde dabei ist nur das er zu flackern anfängt.
     

  2. #2
    Avatar von schnuffie
    schnuffie schnuffie ist offline Mitglied Platin
    Registriert seit
    Oct 2004
    Ort
    Ober-Roden (Hessen)
    Beiträge
    725
    Dafür gibt's elegante Lösungen im Java-Buch:

    http://download.javabuch.de/hjp3html.zip

    Kapitel: 34.2.3 Animation mit Grafikprimitiven

    CU schnuffie
     

  3. #3
    Registriert seit
    Jun 2002
    Ort
    Saarbrücken (Saarland)
    Beiträge
    9.886
    Blog-Einträge
    29
    Hallo!

    Schau mal hier:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    
    package de.tutorials;
     
    import java.awt.Graphics2D;
    import java.awt.image.BufferStrategy;
     
    import javax.swing.JFrame;
     
    public class FlyBall extends JFrame {
        
        private BufferStrategy strategy;
        
        private Thread animator = new Thread(){
            int x, y;
            public void run(){
                while(true){
                    Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                    g.clearRect(0,0,320,240);
                    g.fillOval((x+=4) % 320,(y+=3) % 240,25,25);
                    g.dispose();
                    strategy.show();
                    try {
                        Thread.sleep(20L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        
        public FlyBall(){
            super("BallJumb");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setIgnoreRepaint(true);
            setSize(320,240);
            setVisible(true);
            createBufferStrategy(2);
            strategy = getBufferStrategy();
        }
     
        public static void main(String[] args) {
            new FlyBall().start();
        }
     
        private void start() {
            animator.start();
        }
    }

    Gruß Tom
     
    Java rocks!
    How to become a good Java Programmer?
    Does IT in Java and .Net
    The only valid measurement of code quality: WTFs / minute
    Blog
    Xing
    Twitter

Ähnliche Themen

  1. "XPresso" - Partikel in bestimmte Richtung bewegen
    Von duffypuffy im Forum Cinema 4D
    Antworten: 3
    Letzter Beitrag: 10.07.07, 12:49
  2. Bilder in einem Video "bewegen"
    Von Hanselmann im Forum Videoschnitt, Videotechnik & -produktion
    Antworten: 4
    Letzter Beitrag: 08.09.05, 15:15
  3. Antworten: 4
    Letzter Beitrag: 30.12.04, 19:41
  4. Antworten: 8
    Letzter Beitrag: 20.10.04, 12:52
  5. "MS-DOS-Version" anstatt "Nur Eingabeaufforderung"?
    Von daDom im Forum Virtualisierung (VMWare, Virtual PC & Co.)
    Antworten: 11
    Letzter Beitrag: 21.11.03, 12:36