This doesnt look normal to me:
The Image leaves marks on the screen. Here is all my code:
CatchTheJaffa.java
package net.nivangerow.yogscast.catchthejaffa; import javax.swing.*; import java.awt.*; public class CatchTheJaffa extends JFrame{ public static void main(String[] args) { JFrame frame = new JFrame("Catch the Jaffa"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(640, 480); frame.setVisible(true); frame.setResizable(false); frame.setBackground(Color.BLACK); frame.add(new Game()); } }
Game.java
package net.nivangerow.yogscast.catchthejaffa; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Game extends JPanel implements ActionListener{ Timer time; Honeydew hd; public Game() { setVisible(true); setSize(640, 480); setFocusable(true); hd=new Honeydew(); time = new Timer(5, this); time.start(); addKeyListener(new AL()); } public void actionPerformed(ActionEvent ae) { hd.move(); repaint(); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; System.out.println(g2d.drawImage(hd.img, hd.x, hd.y, null)+" "+hd.x); g2d.drawImage(hd.img, hd.x, hd.y, null); } public class AL extends KeyAdapter { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if(key==KeyEvent.VK_A) hd.px=-1; if(key==KeyEvent.VK_D) hd.px=+1; } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if(key==KeyEvent.VK_A) hd.px=0; if(key==KeyEvent.VK_D) hd.px=0; } } }
Honeydew.java
package net.nivangerow.yogscast.catchthejaffa; import javax.swing.*; import java.awt.*; public class Honeydew { Image img; ImageIcon i = new ImageIcon(getClass().getResource("honeydew.png")); int x, y, px; public Honeydew() { img = i.getImage(); y=340; } public void move() { x = x + px; } }
And the image itself:
Thanks in advance.