本文整理汇总了Java中com.almasb.fxgl.entity.RenderLayer类的典型用法代码示例。如果您正苦于以下问题:Java RenderLayer类的具体用法?Java RenderLayer怎么用?Java RenderLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RenderLayer类属于com.almasb.fxgl.entity包,在下文中一共展示了RenderLayer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initBackground
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
private void initBackground() {
Rectangle bg0 = new Rectangle(getWidth(), getHeight(),
new LinearGradient(getWidth() / 2, 0, getWidth() / 2, getHeight(),
false, CycleMethod.NO_CYCLE,
new Stop(0.2, Color.AQUA), new Stop(0.8, Color.BLACK)));
Rectangle bg1 = new Rectangle(getWidth(), getHeight(), Color.color(0, 0, 0, 0.2));
bg1.setBlendMode(BlendMode.DARKEN);
EntityView bg = new EntityView(RenderLayer.BACKGROUND);
bg.addNode(bg0);
bg.addNode(bg1);
// we add IrremovableComponent because regardless of the level
// the background and screen bounds stay in the game world
Entities.builder()
.viewFromNode(bg)
.with(new IrremovableComponent())
.buildAndAttach(getGameWorld());
Entity screenBounds = Entities.makeScreenBounds(40);
screenBounds.addComponent(new IrremovableComponent());
getGameWorld().addEntity(screenBounds);
}
示例2: initGame
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
@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
view.setRenderLayer(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)
.buildAndAttach(getGameWorld());
}
示例3: spawn
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
private Entity spawn(Card card, int x, int y) {
Entity cardEntity = (Entity) getGameWorld().spawn("Card", new SpawnData(x, y).put("card", card));
cardEntity.getView().setOnMouseClicked(e -> {
if (card.canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
Animation<?> animation = Entities.animationBuilder()
.duration(Duration.seconds(0.35))
.translate(cardEntity)
.from(cardEntity.getPosition())
.to(new Point2D(350, 225))
.build();
animation.setOnFinished(() -> {
player.removeCard(cardEntity);
playerHandChanged = true;
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
currentCard = cardEntity;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
// apply special effect
switch (card.getRank()) {
case SP_PLUS2:
break;
case SP_PLUS4:
break;
case SP_SKIP:
break;
default:
}
aiMove();
});
animation.startInPlayState();
}
});
return cardEntity;
}
示例4: aiMove
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
private void aiMove() {
Entity chosenCard = null;
for (Entity card : enemy.cardsProperty()) {
// can we avoid calls like this?
if (card.getComponent(CardComponent.class).getValue().canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
enemy.removeCard(card);
card.setPosition(new Point2D(350, 225));
currentCard = card;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
// apply special effect
chosenCard = card;
break;
}
}
if (chosenCard == null) {
while (deck.hasCards()) {
Entity draw = spawn(deck.drawCard(), 0, -150);
if (draw.getComponent(CardComponent.class).getValue().canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
draw.setPosition(new Point2D(350, 225));
currentCard = draw;
currentCard.setRenderLayer(RenderLayer.BACKGROUND);
// apply special effect
break;
} else {
enemy.addCard(draw);
}
}
}
}
示例5: initGame
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
@Override
protected void initGame() {
getGameWorld().addEntity(Entities.makeScreenBounds(50));
PhysicsComponent physics = new PhysicsComponent();
Entity block = Entities.builder()
.at(200, 200)
.viewFromNodeWithBBox(new Rectangle(50, 50))
.with(physics)
.buildAndAttach(getGameWorld());
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball =Entities.builder()
.at(200, 300)
.bbox(new HitBox("main", BoundingShape.circle(15)))
.viewFromNode(getAssetLoader().loadTexture("ball.png", 30, 30))
.with(physics2)
.buildAndAttach(getGameWorld());
Line line = new Line();
line.setStartX(block.getCenter().getX());
line.setStartY(block.getCenter().getY());
//line.startXProperty().bind(block.getPositionComponent().xProperty());
//line.startYProperty().bind(block.getPositionComponent().yProperty());
line.endXProperty().bind(ball.getPositionComponent().xProperty().add(15));
line.endYProperty().bind(ball.getPositionComponent().yProperty().add(15));
getGameScene().addGameView(new EntityView(line, RenderLayer.BACKGROUND));
RevoluteJointDef rDef = new RevoluteJointDef();
rDef.bodyA = physics.getBody();
rDef.bodyB = physics2.getBody();
rDef.collideConnected = false;
rDef.localAnchorA = new Vec2(0, 0);
rDef.localAnchorB = new Vec2(0, 5);
rDef.enableLimit = true;
rDef.lowerAngle = FXGLMath.degreesToRadians * -180.0f;
rDef.upperAngle = FXGLMath.degreesToRadians * 180.0f;
rDef.enableMotor = true;
rDef.motorSpeed = FXGLMath.degreesToRadians * 30;
rDef.maxMotorTorque = 15.0f;
joint = (RevoluteJoint) getPhysicsWorld().getJBox2DWorld().createJoint(rDef);
}
示例6: getRenderLayer
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
/**
* @return render layer
*/
public RenderLayer getRenderLayer() {
return view.getRenderLayer();
}
示例7: renderLayerProperty
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
/**
* @return render layer property
*/
public ObjectProperty<RenderLayer> renderLayerProperty() {
return view.renderLayerProperty();
}
示例8: ViewComponent
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
/**
* Creates view component with given render layer.
*
* @param renderLayer render layer to use for view
*/
public ViewComponent(RenderLayer renderLayer) {
view.setRenderLayer(renderLayer);
}
示例9: setRenderLayer
import com.almasb.fxgl.entity.RenderLayer; //导入依赖的package包/类
/**
* Set render layer.
*
* @param renderLayer render layer
*/
public void setRenderLayer(RenderLayer renderLayer) {
view.setRenderLayer(renderLayer);
}