@Override
 public void dispose() {
   super.dispose();
   spriteBatch.dispose();
   shapeRenderer.dispose();
   resourceManager.unloadAll();
 }
Exemplo n.º 2
0
  @Override
  public void apply(Entity entity) {
    String spriteId = parameters.get("spriteId");

    // default world scale, considering viewport 800f
    float worldScale = 0.015625f;

    Float x = parameters.get("x");
    Float y = parameters.get("y");

    Float speed = parameters.get("speed");

    Integer layer = parameters.get("layer");

    Sprite sprite = resourceManager.getResourceValue(spriteId);
    if (sprite == null)
      throw new RuntimeException(
          "Failed to instantiate static sprite, " + spriteId + " not found.");

    entity.setGroup(Groups.Clouds);

    // SpriteUtils.resize(sprite, worldWidth);

    final float cloudSize = 2f;

    float width = sprite.getWidth() * worldScale * cloudSize;
    float height = sprite.getHeight() * worldScale * cloudSize;

    SpriteComponent spriteComponent = new SpriteComponent(sprite);

    spriteComponent.getColor().set(1f, 1f, 1f, 0f);
    Synchronizers.transition(
        spriteComponent.getColor(),
        Transitions.transitionBuilder().start(new Color(1f, 1f, 1f, 0f)).end(Color.WHITE).time(1f));

    entity.addComponent(new SpatialComponent(new SpatialImpl(x, y, width, height, 0f)));
    entity.addComponent(new PreviousStateSpatialComponent());
    entity.addComponent(spriteComponent);
    entity.addComponent(new RenderableComponent(layer));

    entity.addComponent(new BoundsComponent(new Rectangle(0f, 0f, width, height)));
    entity.addComponent(new MovementComponent(new Vector2(speed, 0f), 0f));
  }