Cult3D改變材質顏色的java代碼

來源:互聯網
上載者:User

Cult3D改變材質顏色的java代碼

樣使用這個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() { } }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.