use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class RangeTest method spawnEntity.
private void spawnEntity(double x, double y) {
Entity entity = new Entity();
entity.getPositionComponent().setValue(x, y);
entity.getViewComponent().setView(new EntityView(new Rectangle(40, 40)), true);
getGameWorld().addEntity(entity);
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class PhysicsParticlesSample method initGround.
private void initGround() {
Entity ground = new Entity();
ground.getPositionComponent().setValue(100, 500);
ground.getViewComponent().setView(new EntityView(new Rectangle(800, 100)), true);
ground.addComponent(new PhysicsComponent());
getGameWorld().addEntity(ground);
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class ColoringSample method initUI.
@Override
protected void initUI() {
getGameScene().setBackgroundColor(Color.color(0.75, 0.75, 0.75));
Texture original = texture("player2.png");
// long start = System.nanoTime();
//
// original.blend(new Rectangle(100, 100, Color.RED), BlendMode.ADD);
//
// System.out.println(System.nanoTime() - start);
//
// start = System.nanoTime();
//
// original.manualBlend(new Rectangle(100, 100, Color.RED), BlendMode.ADD);
//
// System.out.println(System.nanoTime() - start);
LinearGradient gradient = new LinearGradient(0.5, 0, 0.5, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.RED), new Stop(1, Color.YELLOW));
EntityView view = new EntityView();
Texture outline1 = original.toColor(Color.BLACK);
view.addNode(outline1);
outline1.setTranslateX(1);
Texture outline2 = original.toColor(Color.BLACK);
view.addNode(outline2);
outline2.setTranslateX(-1);
Texture outline3 = original.toColor(Color.BLACK);
view.addNode(outline3);
outline3.setTranslateY(1);
Texture outline4 = original.toColor(Color.BLACK);
view.addNode(outline4);
outline4.setTranslateY(-1);
view.addNode(original.copy());
HBox hbox = new HBox(20, makeBox("Original", original), makeBox("Outline", view), // makeBox("Grayscale", original.toGrayscale()),
makeBox("Darker", original.darker()), makeBox("Brighter", original.brighter()), makeBox("Invert", original.invert()), makeBox("Saturate", original.saturate().saturate().saturate()));
HBox hbox2 = new HBox(20, makeBox("Soft: self", original.blend(original.copy(), BlendMode.SOFT_LIGHT)), makeBox("Add: red", original.blend(new Rectangle(200, 100, Color.RED), BlendMode.ADD)), makeBox("Red on blue", original.blend(new Rectangle(200, 100, Color.BLUE), BlendMode.RED)), makeBox("Color: red", original.toColor(Color.RED)), makeBox("Mult: red", original.multiplyColor(Color.RED)), makeBox("Screen: RY", original.blend(new Rectangle(200, 100, gradient), BlendMode.SCREEN)));
Texture brick1 = texture("brick.png");
brick1.setScaleX(1.5);
brick1.setScaleY(1.5);
Texture brick2 = texture("brick.png");
brick2.setScaleX(1.5);
brick2.setScaleY(1.5);
Texture brick3 = texture("brick.png");
brick3.setScaleX(1.5);
brick3.setScaleY(1.5);
Texture brick4 = texture("brick.png");
brick4.setScaleX(1.5);
brick4.setScaleY(1.5);
Texture ship1 = original.copy();
ship1.setScaleX(0.7);
ship1.setScaleY(0.7);
HBox hbox3 = new HBox(20, makeBox("Texture 2", texture("brick.png")), makeBox("Diff", original.blend(brick1, BlendMode.DIFFERENCE)), makeBox("Diff^-1", brick3.blend(ship1, BlendMode.DIFFERENCE)), makeBox("Overlay", original.blend(brick2, BlendMode.OVERLAY)), makeBox("Exclusion", original.blend(brick4, BlendMode.EXCLUSION)));
hbox.setTranslateY(50);
hbox2.setTranslateY(250);
hbox3.setTranslateY(450);
Text t = getUIFactory().newText("Texture v Texture Blend", Color.WHITE, 24);
getUIFactory().centerText(t, getWidth() / 2, getHeight() - 150);
getGameScene().addUINodes(hbox, hbox2, hbox3, t);
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class ViewComponent method setTexture.
/**
* Convenience method to set texture as view.
*
* @param textureName name of texture
* @param generateBoundingBox generate bbox from view flag
*/
public void setTexture(String textureName, boolean generateBoundingBox) {
EntityView view = new EntityView(FXGL.getAssetLoader().loadTexture(textureName));
setView(view, generateBoundingBox);
}
use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.
the class RenderLayerSample method initGame.
@Override
protected void initGame() {
Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40)).buildAndAttach(getGameWorld());
EntityView view = new EntityView(new Rectangle(40, 40, Color.RED));
// 1. predefine or create dynamically like below
RenderLayer layer = new RenderLayer() {
@Override
public String name() {
// 2. specify the unique name for that layer
return "LAYER_BELOW_PLAYER";
}
@Override
public int index() {
// 3. specify layer index, higher values will be drawn above lower values
return 1000;
}
};
// we have added box after player but because of the render layer we specified
// the red box will be drawn below the player
Entities.builder().at(80, 80).viewFromNode(view).renderLayer(layer).buildAndAttach(getGameWorld());
}
Aggregations