Search in sources :

Example 11 with EntityView

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);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle)

Example 12 with EntityView

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);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle)

Example 13 with EntityView

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);
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) HBox(javafx.scene.layout.HBox) Stop(javafx.scene.paint.Stop) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) Texture(com.almasb.fxgl.texture.Texture)

Example 14 with EntityView

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);
}
Also used : EntityView(com.almasb.fxgl.entity.view.EntityView)

Example 15 with EntityView

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());
}
Also used : EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle) RenderLayer(com.almasb.fxgl.entity.RenderLayer)

Aggregations

EntityView (com.almasb.fxgl.entity.view.EntityView)15 Rectangle (javafx.scene.shape.Rectangle)10 Entity (com.almasb.fxgl.entity.Entity)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)2 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)2 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)2 GameApplication (com.almasb.fxgl.app.GameApplication)1 Vec2 (com.almasb.fxgl.core.math.Vec2)1 Control (com.almasb.fxgl.entity.Control)1 Entities (com.almasb.fxgl.entity.Entities)1 RenderLayer (com.almasb.fxgl.entity.RenderLayer)1 Required (com.almasb.fxgl.entity.component.Required)1 ViewComponent (com.almasb.fxgl.entity.component.ViewComponent)1 OffscreenCleanControl (com.almasb.fxgl.entity.control.OffscreenCleanControl)1 ProjectileControl (com.almasb.fxgl.entity.control.ProjectileControl)1 Input (com.almasb.fxgl.input.Input)1 UserAction (com.almasb.fxgl.input.UserAction)1 HitBox (com.almasb.fxgl.physics.HitBox)1 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)1 RevoluteJointDef (com.almasb.fxgl.physics.box2d.dynamics.joints.RevoluteJointDef)1