1. Image im这是全局变量。 当你在panel中已经声明为全局, 那么gameRender即离屏绘制的时候就不要再声明一个image im了, 否则在gamePaint即屏幕显示的是同一个im。
2. Graphics有drawImage方法:
public abstract booleandrawImage( Image img,
int x,
int y,
ImageObserver observer)
img
- 要绘制的指定图像。如果
img
为 null,则此方法不执行任何操作。
x
-
x 坐标。
y
-
y 坐标。
observer
- 转换了更多图像时要通知的对象。
public abstract boolean drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer)
img
- 要绘制的指定图像。如果
img
为 null,则此方法不执行任何操作。
dx1
- 目标矩形第一个角的
x 坐标。
dy1
- 目标矩形第一个角的
y 坐标。
dx2
- 目标矩形第二个角的
x 坐标。
dy2
- 目标矩形第二个角的
y 坐标。
sx1
- 源矩形第一个角的
x 坐标。
sy1
- 源矩形第一个角的
y 坐标。
sx2
- 源矩形第二个角的
x 坐标。
sy2
- 源矩形第二个角的
y 坐标。
observer
- 当缩放并转换了更多图像时要通知的对象。
private void drawRibbon(Graphics g, BufferedImage im,int dx1, int dx2, int sx1, int sx2)
/* The y-coords of the image always starts at 0 and ends at
pHeight (the height of the panel), so are hardwired.
*/
{
g.drawImage(im, dx1, 0, dx2, pHeight,sx1, 0, sx2, pHeight, null);
}
产生做这个游戏是我从网上看了有人做了一个c++写的游戏, 所以我实训的时候就用java做了一个, 游戏界面与之前类似, 但实现原理截然不同