Android Open Source - mobius Fadable Layer






From Project

Back to project page mobius.

License

The source code is released under:

MIT License

If you think the Android project mobius listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sgtcodfish.mobiusListing.components;
//w ww.java 2  s.c o  m
import com.badlogic.gdx.maps.MapProperties;
import com.sgtcodfish.mobiusListing.WorldConstants;

/**
 * @author Ashley Davis (SgtCoDFish)
 */
public class FadableLayer extends InteractableLayer<Opacity> {
  protected final float  BECOMING_OPAQUE      = 1.0f;
  protected final float  BECOMING_TRANSPARENT  = -1.0f;

  protected float      minOpacity        = WorldConstants.GLOBAL_PASSTHROUGH_OPACITY;
  protected float      opacityDirection    = BECOMING_TRANSPARENT;

  @Override
  public void interact(Opacity c, int degree) {
    c.opacity += opacityDirection * degree;

    if (c.opacity <= minOpacity) {
      c.opacity = minOpacity;
      opacityDirection = BECOMING_OPAQUE;
    } else if (c.opacity >= 1.0f) {
      c.opacity = 1.0f;
      opacityDirection = BECOMING_TRANSPARENT;
    }
  }

  /**
   * <p>
   * Sets up a FadableLayer with the given opacity details.
   * </p>
   * <p>
   * <em>Note:</em> this function checks and sets up the opacity based on
   * {@link WorldConstants#GLOBAL_SOLID_OPACITY_THRESHOLD}.
   * </p>
   * 
   * @param c
   * @param tiledOpacity
   * @param properties
   */
  public void setupOpacity(Opacity c, float tiledOpacity, MapProperties properties) {
    if (tiledOpacity < WorldConstants.GLOBAL_SOLID_OPACITY_THRESHOLD) {
      c.setTransparent();
      opacityDirection = BECOMING_OPAQUE;
    } else {
      c.setOpaque();
      opacityDirection = BECOMING_TRANSPARENT;
    }
  }

  @Override
  public void fromTiledProperties(MapProperties properties) {
    String prop = properties.get("minOpacity", null, String.class);

    if (prop != null) {
      float minOpacity = -1.0f;

      try {
        minOpacity = Float.parseFloat(prop);
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException("Invalid value for opacity: " + prop);
      }

      this.minOpacity = minOpacity;

    } else {
      throw new IllegalArgumentException("Trying to load FadableLayer from layer with no minOpacity!");
    }
  }
}




Java Source Code List

com.sgtcodfish.mobiusListing.Item.java
com.sgtcodfish.mobiusListing.MobiusListingGame.java
com.sgtcodfish.mobiusListing.TerrainCollisionMap.java
com.sgtcodfish.mobiusListing.WorldConstants.java
com.sgtcodfish.mobiusListing.android.AndroidLauncher.java
com.sgtcodfish.mobiusListing.components.ChildLinked.java
com.sgtcodfish.mobiusListing.components.Collectable.java
com.sgtcodfish.mobiusListing.components.DxLayer.java
com.sgtcodfish.mobiusListing.components.DyLayer.java
com.sgtcodfish.mobiusListing.components.FadableLayer.java
com.sgtcodfish.mobiusListing.components.FocusTaker.java
com.sgtcodfish.mobiusListing.components.InteractableLayer.java
com.sgtcodfish.mobiusListing.components.Interactable.java
com.sgtcodfish.mobiusListing.components.Inventory.java
com.sgtcodfish.mobiusListing.components.Linked.java
com.sgtcodfish.mobiusListing.components.MobiusSprite.java
com.sgtcodfish.mobiusListing.components.MovingLayer.java
com.sgtcodfish.mobiusListing.components.Opacity.java
com.sgtcodfish.mobiusListing.components.PlatformInputListener.java
com.sgtcodfish.mobiusListing.components.PlatformSprite.java
com.sgtcodfish.mobiusListing.components.PlayerInputListener.java
com.sgtcodfish.mobiusListing.components.PlayerSprite.java
com.sgtcodfish.mobiusListing.components.PlayerState.java
com.sgtcodfish.mobiusListing.components.Position.java
com.sgtcodfish.mobiusListing.components.Solid.java
com.sgtcodfish.mobiusListing.components.StaticSprite.java
com.sgtcodfish.mobiusListing.components.TiledRenderable.java
com.sgtcodfish.mobiusListing.components.Velocity.java
com.sgtcodfish.mobiusListing.desktop.DesktopLauncher.java
com.sgtcodfish.mobiusListing.levels.LevelEntityFactory.java
com.sgtcodfish.mobiusListing.player.HumanoidAnimationState.java
com.sgtcodfish.mobiusListing.player.PlayerConstants.java
com.sgtcodfish.mobiusListing.player.PlayerEntityFactory.java
com.sgtcodfish.mobiusListing.systems.AudioSystem.java
com.sgtcodfish.mobiusListing.systems.CollisionBoxRenderingDebugSystem.java
com.sgtcodfish.mobiusListing.systems.FocusTakerSystem.java
com.sgtcodfish.mobiusListing.systems.LevelAdvanceSystem.java
com.sgtcodfish.mobiusListing.systems.LinkingSystem.java
com.sgtcodfish.mobiusListing.systems.MovementSystem.java
com.sgtcodfish.mobiusListing.systems.PlatformInputSystem.java
com.sgtcodfish.mobiusListing.systems.PlayerInputSystem.java
com.sgtcodfish.mobiusListing.systems.SolidProcessingSystem.java
com.sgtcodfish.mobiusListing.systems.SpriteRenderingSystem.java
com.sgtcodfish.mobiusListing.systems.TerrainCollisionBoxRenderingDebugSystem.java
com.sgtcodfish.mobiusListing.systems.TerrainCollisionSystem.java
com.sgtcodfish.mobiusListing.systems.TiledRenderingSystem.java