![](/img/trans.png)
[英]Getting Height and Width of Image in Java without an ImageObserver
[英]Draw Image and ImageObserver in Java Applet
我正在使用小程序制作游戲,我想讓我的角色能夠在自己的課堂上畫畫。 目前,這就是我正在做的事情:
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);
}
問題是我不知道如何指定ImageObserver。 GameMain.class是applet,但是當我這樣說時,我收到一條錯誤,上面寫着“找不到符號”。
我怎么能告訴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.