简体   繁体   English

在Java Applet中绘制Image和ImageObserver

[英]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. 问题是我不知道如何指定ImageObserver。 GameMain.class is the applet, but when I say this I get an error that says "cannot find symbol." GameMain.class是applet,但是当我这样说时,我收到一条错误,上面写着“找不到符号”。

How can I tell java where to draw it? 我怎么能告诉java在哪里绘制它?

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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