Cult3D 高级教程之改变材质颜色的java代码

时间:2011-05-12 关注公众号 来源:网络

  样使用这个class:
  定义一个新的颜色color,比如" private Color red = new Color ( 198, 58, 41); " 增加该颜色的变量名variable name到colors数组,使用changeColor方法来循环改变颜色。

  修改如下设置
import com.cult3D.*; import com.cult3d.world.*; import Java.awt.Color; import java.awt.Image; import java.awt.Graphics; public class ColorSwap implements Cult3DScript, Runnable { // TEXTURE_NAME 的值是你要改变得纹理的名字 private static final String TEXTURE_NAME = "MADAROSE"; // if you want to add more colors add a Color instance here // and add it to the colors array. The numbers are in RGB values (0 to 255, where 0 is black and 255 is white) private Color red = new Color(198, 58, 41); private Color blue = new Color(99, 93, 163); private Color GREEN = new Color(138, 149, 78); private Color grey = new Color(136, 136, 136); private Color lightBlue = new Color(121, 130, 173); private Color black = new Color(64, 64, 64); private Color[] colors = {red, blue, green, grey, lightBlue, black }; /////////////////////////////////////////////////////////////////////////// private Texture texture; private TextureImage textureImage; private int textureWidth, textureHeight; private Graphics graphics; // declare this variable volatile, so it always Keeps the right value private volatile boolean loaded = false; private int colorCounter = 0; // Standard constructor public ColorSwap() { Thread thread = new Thread(this); thread.start(); } // Thread method which loads "heavy" resources/textures // To avoid the viewer hang when loading. public void run() { texture = new Texture(TEXTURE_NAME); textureWidth = texture.getWidth(); textureHeight = texture.getHeight(); textureImage = (TextureImage)Cult.createImage(textureWidth, textureHeight); graphics = textureImage.getGraphics(); loaded = true; } /* Note: Lines started with two slashes (//) is line comments and is not in the final class file, Lines with slash-star is another comment which is called "block comment" which comments a block of code until it encounters star-slash. As */ // use this method from the Designer to loop the colors. public void changeColor(String s) { if (!loaded) { System.out.println("The Java code is not yet loaded"); return; } if (colorCounter >= colors.length) { colorCounter = 0; } switchColor(colors[colorCounter]); colorCounter++; } // The actual color change private void switchColor(Color color) { graphics.setColor(color); graphics.fillRect(0,0, textureWidth,textureHeight); texture.setTexture(textureImage); } public void cult3dDestroy() { } }

阅读全文
扫码关注“ 多特资源库
更多更全的软件资源下载
文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站)
玩家热搜

相关攻略

正在加载中
版权
版权说明

文章内容来源于网络,不代表本站立场,若侵犯到您的权益,可联系我们删除。(本站为非盈利性质网站)

电话:13918309914

QQ:1967830372

邮箱:rjfawu@163.com

toast