本文整理汇总了Java中com.badlogic.ashley.core.Component类的典型用法代码示例。如果您正苦于以下问题:Java Component类的具体用法?Java Component怎么用?Java Component使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Component类属于com.badlogic.ashley.core包,在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeEnviromentGestalt
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
public static Component makeEnviromentGestalt() {
ObjImporter importer = new ObjImporter();
try {
importer.load("assets/models/cave.obj");
} catch (IOException e) {
e.printStackTrace();
}
MeshBuilder objBuilder = new SegmentedMeshBuilder(Primitive.TRIANGLES);
Mesh enviromentMesh = importer.make(objBuilder);
Gestalt g = new Gestalt();
g.mesh = enviromentMesh;
g.shader = new ShaderBuilder()
.setVertexShader("assets/shaders/cc/depth.vert.glsl")
.setFragmentShader("assets/shaders/cc/depth.frag.glsl")
.build();
g.texture0 = new TextureBuilder().setContents("assets/textures/RockPerforated0029_1_seamless_S.png").build();
g.texture4 = new TextureBuilder().setContents("assets/textures/fog-gradient-03.png").build(); // texture4 is used for fog texture gradient
g.uvscale = 12f;
return g;
}
示例2: saveToJson
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
public String saveToJson() {
gameState.stopThread();
try {
ImmutableArray<Entity> entities = gameState.getEntityEngine().getEntities();
SavedGame savedGame = new SavedGame();
for (Entity entity : entities) {
List<ComponentContainer> componentContainers = new ArrayList<ComponentContainer>();
for (Component c : entity.getComponents()) {
componentContainers.add(new ComponentContainer(c));
}
EntityContainer entityContainer = new EntityContainer(entity.getId(), entity.getClass().getName(), componentContainers);
savedGame.entitiesContainers.add(entityContainer);
}
return new GsonBuilder().enableComplexMapKeySerialization().create().toJson(savedGame);
} catch (Exception e) {
e.printStackTrace();
}
gameState.startThread();
return "Failed";
}
示例3: addedToEngine
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public void addedToEngine(Engine engine) {
for (int i = 0; permutations.length > i; i++) {
Array<Class<? extends Component>> components = new Array<Class<? extends Component>>();
for (int classIndex = 0, s = (int)(rng.nextFloat() * 7) + 3; s > classIndex; classIndex++) {
components.add(types.get((int)(rng.nextFloat() * types.size)));
}
permutations[i] = components;
}
this.engine = engine;
entities = engine.getEntitiesFor(Family.all().get());
for (int i = 0; ENTITY_COUNT > i; i++)
createEntity();
}
示例4: reset
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
/**
* Resets components to default state
*/
public void reset() {
for (Entity entity : ashley.getEntitiesFor(Family.all().get())) {
for (Component component : entity.getComponents()) {
((ZBComponent)component).reset();
}
if (entity.getComponent(Box2DComponent.class) != null)
{
entity.getComponent(Box2DComponent.class).body.setAwake(true);
entity.getComponent(Box2DComponent.class).body.setTransform(
entity.getComponent(TransformComponent.class).origX,
entity.getComponent(TransformComponent.class).origY,
entity.getComponent(TransformComponent.class).origRotation * MathUtils.degRad
);
}
}
// TODO: Day-night system reset
}
示例5: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
public <C extends Component> C getComponent(Class<C> clazz) {
C comp = null;
if (entity.getComponent(clazz) != null) {
comp = (C) entity.getComponent(clazz);
} else {
Class<? extends LogicBrickSystem>[] systems = engine.getSystemClass(clazz);
if(systems != null) {
for (Class<? extends LogicBrickSystem> system : systems) {
if (system != null) getSystem(system);
}
}
comp = engine.createComponent(clazz);
entity.add(comp);
}
if(comp instanceof CameraComponent) ((CameraComponent) comp).camera = engine.getGameContext().get(Camera.class);
return comp;
}
示例6: getEntity
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
public Entity getEntity() {
for (Component c : entity.getComponents()) {
if (c instanceof SensorComponent) {
config(((SensorComponent) c).sensors, entity);
}
if (c instanceof ControllerComponent) {
config(((ControllerComponent) c).controllers, entity);
}
if (c instanceof ActuatorComponent) {
config(((ActuatorComponent) c).actuators, entity);
}
}
controllerStates.clear();
return entity;
}
示例7: toEngineComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
/**
* Converts a model component into an engine component
*/
public Component toEngineComponent(ModelComponent component) {
ComponentProcessor componentProcessor = componentProcessorMap
.get(component.getClass());
if (componentProcessor != null) {
component = EngineUtils.buildWithParameters(gameAssets,
variablesManager, component);
Component engineComponent = componentProcessor
.getComponent(component);
// Update modelToEngine mapping, if needed
if (engineComponent != null
&& !modelToEngineComponents.containsKey(component
.getClass())) {
modelToEngineComponents.put(component.getClass(),
engineComponent.getClass());
}
return engineComponent;
}
return null;
}
示例8: addComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
/**
* Adds the given engine component to the entity.
*/
public void addComponent(EngineEntity entity, Component c) {
if (c != null) {
if (c instanceof MultiComponent) {
for (Component component : ((MultiComponent) c).getComponents()) {
addComponent(entity, component);
}
} else {
entity.add(c);
// Special cases
if (c instanceof RendererComponent) {
entity.addRenderer(((RendererComponent) c).getEntityGroup());
} else if (c instanceof ShaderComponent) {
entity.setShader((ShaderComponent) c);
}
}
}
}
示例9: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public Component getComponent(Shader shader) {
ShaderComponent shaderComponent = gameLoop
.createComponent(ShaderComponent.class);
shaderComponent.setVariablesManager(variablesManager);
ShaderProgram shaderProgram = shaders.get(shader.getUri());
if (shaderProgram == null) {
shaderProgram = new ShaderProgram(VERTEX_SHADER, gameAssets
.resolve(shader.getUri()).readString());
if (!shaderProgram.isCompiled()) {
Gdx.app.error("ShaderProcessor", "Error parsing shader: "
+ shaderProgram.getLog());
}
shaders.put(shader.getUri(), shaderProgram);
}
shaderComponent.setShaderProgram(shaderProgram);
for (Parameter parameter : shader.getUniforms()) {
String[] values = ((String) parameter.getValue()).split(",");
shaderComponent.setUniform(parameter.getName(), values);
}
return shaderComponent;
}
示例10: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Component getComponent(Behavior behavior) {
Event event = behavior.getEvent();
Class<? extends BehaviorComponent> componentClass = componentClassForEvent(event
.getClass());
if (componentClass != null) {
BehaviorComponent component = gameLoop
.createComponent(componentClass);
component.addBehavior(behavior.getEvent(), behavior.getEffects());
return component;
} else {
Gdx.app.error("BehaviorsProcessor",
"No component/setter for event " + event.getClass());
}
return null;
}
示例11: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public Component getComponent(Label component) {
Skin skin = gameAssets.getSkin();
LabelComponent label = gameLoop.createComponent(LabelComponent.class);
label.setVariablesManager(variablesManager);
LabelStyle style = skin.get(component.getStyle(), LabelStyle.class);
LabelStyle styleCopy = new LabelStyle(style);
Color color = component.getColor();
if (color != null) {
styleCopy.fontColor.set(color.getR(), color.getG(), color.getB(),
color.getA());
}
label.setControl(new com.badlogic.gdx.scenes.scene2d.ui.Label("",
styleCopy));
label.getControl().setAlignment(Align.center);
label.setText(gameAssets.getI18N().m(component.getText()));
I18nTextComponent textComponent = gameLoop
.createComponent(I18nTextComponent.class);
textComponent.setI18nKey(component.getText());
textComponent.setTextSetter(label);
return new MultiComponent(label, textComponent);
}
示例12: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public Component getComponent(TextButton component) {
Skin skin = gameAssets.getSkin();
TextButtonComponent button = gameLoop
.createComponent(TextButtonComponent.class);
button.setVariablesManager(variablesManager);
button.setControl(new com.badlogic.gdx.scenes.scene2d.ui.TextButton("",
new TextButtonStyle(skin.get(component.getStyle(),
TextButtonStyle.class))));
button.setText(gameAssets.getI18N().m(component.getText()));
I18nTextComponent textComponent = gameLoop
.createComponent(I18nTextComponent.class);
textComponent.setI18nKey(component.getText());
textComponent.setTextSetter(button);
return new MultiComponent(button, textComponent);
}
示例13: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public Component getComponent(VerticalLayout component) {
VerticalLayoutComponent verticalLayout = gameLoop
.createComponent(VerticalLayoutComponent.class);
for (Control control : component.getControls()) {
addControls(verticalLayout,
componentLoader.toEngineComponent(control));
}
VerticalGroup group = verticalLayout.getControl();
switch (component.getAlign()) {
case LEFT:
group.left();
break;
case CENTER:
group.center();
break;
case RIGHT:
group.right();
break;
}
group.pack();
return verticalLayout;
}
示例14: combine
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
/**
* Explicitly allow other effects to be started on this same component,
* replacing the currently-running effect. This ensures that all sound
* resources are properly freed.
*
* @param other
* sound to replace current sound with.
* @return
*/
@Override
public synchronized boolean combine(Component other) {
this.reset();
SoundComponent otherSound = (SoundComponent) other;
if (otherSound.sound != null) {
this.sound = otherSound.sound;
this.soundId = otherSound.soundId;
this.soundStart = otherSound.soundStart;
} else if (otherSound.music != null) {
this.music = otherSound.music;
}
this.config = otherSound.config;
this.finished = otherSound.finished;
this.started = otherSound.started;
return true;
}
示例15: getComponent
import com.badlogic.ashley.core.Component; //导入依赖的package包/类
@Override
public Component getComponent(Label component) {
Skin skin = gameAssets.getSkin();
EditableLabelComponent button = gameLoop
.createComponent(EditableLabelComponent.class);
button.initialize(controller, component);
button.setVariablesManager(variablesManager);
TextFieldStyle style = skin.get(component.getStyle(),
TextFieldStyle.class);
TextFieldStyle styleCopy = new TextFieldStyle(style);
button.setStyle(styleCopy);
button.setText(gameAssets.getI18N().m(component.getText()));
I18nTextComponent textComponent = gameLoop
.createComponent(I18nTextComponent.class);
textComponent.setI18nKey(component.getText());
textComponent.setTextSetter(button);
return new MultiComponent(button, textComponent);
}