简体   繁体   中英

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?

只为ImageObserver提供null ,这样就可以了。

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

假设drawPlayer()方法在applet类中,上面是正确的解决方案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM