helsont
helsont

Reputation: 4952

Draw Image and ImageObserver in Java Applet

I'm using an applet to make a game and I'd like to make my characters be able to draw themselves in their own class. Currently, this is what I'm doing:

public void drawPlayer(Image img, Graphics g)
{

    g.drawRect(0,0,128,128); //this is a test to see if it would draw a 
                                             //rectangle, which it did
    g.drawImage(img,0,0,128,128,0+128*x,128,128+128*x,128,GameMain);


}

The problem is that I don't know how to specify the ImageObserver. GameMain.class is the applet, but when I say this I get an error that says "cannot find symbol."

How can I tell java where to draw it?

Upvotes: 0

Views: 931

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168815

g.drawImage(img,0,0,128,128,0+128*x,128,128+128*x,128,this);

Above is the correct solution, assuming the drawPlayer() method is in the applet class.

Upvotes: 1

Neet
Neet

Reputation: 4037

Just supply null for ImageObserver, this will do the trick.

Upvotes: 1

Related Questions