Cult3d the Java code that changes the color of the material

Source: Internet
Author: User
Tags comments thread volatile

Sample Use this class:  
Define a new colour color, such as "private color red = new Color (198, 58, 41);" "Add the variable name variable name to the colors array of the color, and use the ChangeColor method to loop the color."

Modify the following settings


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 value is the name of the texture you want to change. private static final String textu Re_name = "Madarose"; If you are want to add colors add a Color instance here//and add it to the colors array. The numbers are in RGB values (0 to 255, where 0 are black and 255 are 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 is 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 lo Ads "heavy" resources/textures//To avoid the viewer hang when loading. public void Run () {texture = new texture (texture_name); texturewidth = Texture.getwidth (); textureheight = Texture.gethei Ght (); Textureimage = (textureimage) cult.createimage (Texturewidth, textureheight); Graphics = Textureimage.getgraphics (); loaded = true; }/* Note:lines started with two slashes (//) is line comments and isn't 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 isn't yet loaded");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, text Urewidth,textureheight); Texture.settexture (Textureimage); public void Cult3ddestroy () {}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.