usetexture.java
来自「关于java游戏的设计代码」· Java 代码 · 共 46 行
JAVA
46 行
// 程序:使用纹理贴图
// 范例文件:UseTexture.java
import java.awt.*;
import java.applet.*;
public class UseTexture extends Applet
{
int ImageWidth,ImageHeight,countX,countY;
Image texture;
MediaTracker MT;
public void init()
{
countX = 5; //X轴使用的纹理数
countY = 5; //Y轴使用的纹理数
//取得纹理图形
texture = getImage(getDocumentBase(),"Images/texture.gif");
MT = new MediaTracker(this);
MT.addImage(texture,0);
try
{
MT.waitForAll();
}
catch(InterruptedException E){ } //没有进行异常处理
ImageWidth = texture.getWidth(this); //纹理宽度
ImageHeight = texture.getHeight(this); //纹理高度
//重设Applet的大小
resize(ImageWidth*countX,ImageHeight*countY);
}
public void paint(Graphics g)
{
//使用纹理填满背景
for(int i=0;i<(countX * countY);i++)
{
g.drawImage(texture,i%countX*ImageWidth,i/countY*ImageHeight,
this);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?