📄 screendrawer.java
字号:
/**
游戏绘制类
Download by http://www.codefans.net
**/
package game.multiplayer;
import javax.microedition.lcdui.*;
public class ScreenDrawer {
//清除绘图屏幕
public static void clearScreen(Graphics g, int width, int height) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, width, height);
}
//绘制图片
public static void drawImage(Graphics g, Image image, int x, int y) {
g.drawImage(image, x, y, 0);
}
//绘制区域图片
public static void drawImage(Graphics g, Image image, int x, int y, int width,
int height, int widthIndex, int heightIndex,
boolean isLeft) {
Image boyImage = Image.createImage(width, height);
Graphics offScreenG = boyImage.getGraphics();
offScreenG.drawImage(image, -width * (widthIndex - 1),
-height * (heightIndex - 1), 0);
//获取图片的长度与宽度
int imgWidth = boyImage.getWidth();
int imgHeight = boyImage.getHeight();
int[] rgb = new int[imgWidth * imgHeight];
//获取当前图片的象素RGB数组
boyImage.getRGB(rgb, 0, imgWidth, 0, 0, imgWidth, imgHeight);
//将背景象素置为透明
for (int i = 0; i < rgb.length; ++i) {
if (rgb[i] == 0xfffcfcff) {
rgb[i] = rgb[i] & 0x00ffffff;
}
}
if (isLeft) {
g.drawImage(Image.createRGBImage(rgb, imgWidth, imgHeight, true), x, y, 0);
}
else {
g.drawImage(Image.createRGBImage(rgb, imgWidth, imgHeight, true), x, y, 3);
}
}
//绘制字符串
public static void drawString(Graphics g, int x, int y, String s) {
g.setColor(0xff0000);
g.drawString(s, x, y, 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -