查看: 2071|回复: 0
打印 上一主题 下一主题

[Cult3D] Cult3D中改变材质颜色的java代码【转】

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2012-9-14 17:06:07 |只看该作者 |倒序浏览
怎样使用这个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 cons***ctor

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***n()

{

texture = new Texture(TEXTURE_NAME);

textureWidth = texture.getWidth();

textureHeight = texture.getHeight();

textureImage = (TextureImage)Cult.createImage(textureWidth, textureHeight);

graphics = textureImage.getGraphics();

loaded = ***e;

}

/*

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()

{

}

}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-6 06:06 , Processed in 0.083024 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部