aurelienribon.tweenengine.equations.Elastic Java Examples

The following examples show how to use aurelienribon.tweenengine.equations.Elastic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TweenUtils.java    From universal-tween-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Takes an easing name and gives you the corresponding TweenEquation.
 * You probably won't need this, but tools will love that.
 *
 * @param easingName The name of an easing, like "Quad.INOUT".
 * @return The parsed equation, or null if there is no match.
 */
public static TweenEquation parseEasing(String easingName) {
	if (easings == null) {
		easings = new TweenEquation[] {Linear.INOUT,
			Quad.IN, Quad.OUT, Quad.INOUT,
			Cubic.IN, Cubic.OUT, Cubic.INOUT,
			Quart.IN, Quart.OUT, Quart.INOUT,
			Quint.IN, Quint.OUT, Quint.INOUT,
			Circ.IN, Circ.OUT, Circ.INOUT,
			Sine.IN, Sine.OUT, Sine.INOUT,
			Expo.IN, Expo.OUT, Expo.INOUT,
			Back.IN, Back.OUT, Back.INOUT,
			Bounce.IN, Bounce.OUT, Bounce.INOUT,
			Elastic.IN, Elastic.OUT, Elastic.INOUT
		};
	}

	for (int i=0; i<easings.length; i++) {
		if (easingName.equals(easings[i].toString()))
			return easings[i];
	}

	return null;
}
 
Example #2
Source File: TweenUtils.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** Takes an easing name and gives you the corresponding TweenEquation. You probably won't need this, but tools will love that.
 * 
 * @param easingName The name of an easing, like "Quad.INOUT".
 * @return The parsed equation, or null if there is no match. */
public static TweenEquation parseEasing (String easingName) {
	if (easings == null) {
		easings = new TweenEquation[] {Linear.INOUT, Quad.IN, Quad.OUT, Quad.INOUT, Cubic.IN, Cubic.OUT, Cubic.INOUT, Quart.IN,
			Quart.OUT, Quart.INOUT, Quint.IN, Quint.OUT, Quint.INOUT, Circ.IN, Circ.OUT, Circ.INOUT, Sine.IN, Sine.OUT,
			Sine.INOUT, Expo.IN, Expo.OUT, Expo.INOUT, Back.IN, Back.OUT, Back.INOUT, Bounce.IN, Bounce.OUT, Bounce.INOUT,
			Elastic.IN, Elastic.OUT, Elastic.INOUT};
	}

	for (int i = 0; i < easings.length; i++) {
		if (easingName.equals(easings[i].toString())) return easings[i];
	}

	return null;
}
 
Example #3
Source File: JumpOverEnemy.java    From xibalba with MIT License 4 votes vote down vote up
@Override
public void act(Entity caster, Entity target) {
  AttributesComponent attributes = ComponentMappers.attributes.get(caster);

  if (attributes.energy >= MovementComponent.COST
      && WorldManager.entityHelpers.isNear(caster, target)) {
    PositionComponent casterPosition = ComponentMappers.position.get(caster);
    PositionComponent targetPosition = ComponentMappers.position.get(target);

    float newPositionX = targetPosition.pos.x;
    float newPositionY = targetPosition.pos.y;

    if (casterPosition.pos.x < targetPosition.pos.x) {
      newPositionX += 1;
    } else if (casterPosition.pos.x > targetPosition.pos.x) {
      newPositionX -= 1;
    }

    if (casterPosition.pos.y < targetPosition.pos.y) {
      newPositionY += 1;
    } else if (casterPosition.pos.y > targetPosition.pos.y) {
      newPositionY -= 1;
    }

    Vector2 newPosition = new Vector2(newPositionX, newPositionY);

    if (!WorldManager.mapHelpers.isBlocked(newPosition)) {
      VisualComponent visual = ComponentMappers.visual.get(caster);

      WorldManager.tweens.add(
          Tween.to(visual.sprite, SpriteAccessor.SCALE, .25f).target(
              1.2f, 1.2f
          ).repeatYoyo(1, 0f).ease(Elastic.INOUT)
      );

      WorldManager.tweens.add(
          Tween.to(visual.sprite, SpriteAccessor.XY, .25f).target(
              newPosition.x * Main.SPRITE_WIDTH, newPosition.y * Main.SPRITE_HEIGHT
          ).setCallback((type, source) -> {
            if (type == TweenCallback.COMPLETE) {
              casterPosition.pos.set(newPosition);
            }
          })
      );
    }
  }
}