Original Post
Ok, i''m fairly new to Java2D API, and so I would appreciate some guidance in the form of animation. As I have just been handed an assignment in which I have to code a 2d game. Here''s some bare minimum code below, just to see that I am understanding it correctly.
CGameObject.java
import java.awt.*;
import java.awt.image.*;
class CGameObject extends Canvas
{
private Graphics m_gfx;
private Image m_image;
//Constructor
public CGameObject()
{
m_gfx = null;
m_image = null;
}
public void paint()
{
Graphics2D g2 = (Graphics2D)m_gfx;
g2.drawImage(m_image); //Don''t worry i''m aware this aint quite right.
}
public void update()
{
BufferedImage im = (BufferedImage)m_image;
paint();
}
}
Biplanes.java
class Biplanes
{
private CGameObject m_background; // Background image (will be static)
private CGameObject m_foreground; // Represents a bi-plane moving
private boolean Running; // Game Running?
//Constructor
public Biplanes()
{
}
public void InitGame()
{
Running = true;
m_background.paint();
m_foreground.paint();
}
public void ExitGame()
{
System.exit(0);
}
public static void main(String[] args)
{
InitGame();
while(Running)
{
m_background.update();
m_foreground.update();
}
ExitGame();
}
}
Also I realise this code doesn''t implement any form of sprites (images with multiple frames), how would this be acheived.
Oh and when I do eventually implement keyboard input, would it be best to implement it within the GameObject class or the main Biplanes class??