Search in sources :

Example 1 with TimelineAnimation

use of com.gemserk.animation4j.timeline.TimelineAnimation in project commons-gdx by gemserk.

the class Actors method topToast.

public static Actor topToast(final String text, final float time, final Skin skin) {
    final Window window = new Window("", skin);
    window.setMovable(false);
    window.defaults().spaceBottom(5);
    Label toastLabel = new Label(text, skin);
    toastLabel.setAlignment(Align.left);
    toastLabel.setWrap(true);
    window.row().fillX().expandX();
    window.add(toastLabel).fillX().padLeft(10);
    window.invalidate();
    window.setKeepWithinStage(false);
    window.setWidth(Gdx.graphics.getWidth() * 0.95f);
    window.setHeight(toastLabel.getTextBounds().height + 20 + window.getStyle().titleFont.getLineHeight());
    window.setX(Gdx.graphics.getWidth() * 0.5f - window.getWidth() * 0.5f);
    float outsideY = Gdx.graphics.getHeight() + window.getHeight();
    float insideY = Gdx.graphics.getHeight() - window.getHeight() + window.getStyle().titleFont.getLineHeight();
    window.setY(outsideY);
    final TimelineAnimation timelineAnimation = //
    Builders.animation(//
    Builders.timeline().value(//
    Builders.timelineValue(window, Scene2dConverters.actorPositionTypeConverter).keyFrame(//
    0f, //
    new float[] { window.getX(), outsideY }, InterpolationFunctions.linear(), //
    InterpolationFunctions.easeIn()).keyFrame(1f, //
    new float[] { window.getX(), insideY }).keyFrame(//
    4f, //
    new float[] { window.getX(), insideY }, InterpolationFunctions.linear(), //
    InterpolationFunctions.easeOut()).keyFrame(5f, //
    new float[] { window.getX(), outsideY }))).started(//
    true).delay(//
    0f).speed(//
    5f / time).build();
    window.addAction(new ActionAdapter() {

        @Override
        public boolean update(float delta) {
            timelineAnimation.update(delta);
            if (timelineAnimation.isFinished()) {
                window.remove();
                return true;
            }
            return false;
        }
    });
    return window;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TimelineAnimation(com.gemserk.animation4j.timeline.TimelineAnimation)

Example 2 with TimelineAnimation

use of com.gemserk.animation4j.timeline.TimelineAnimation in project commons-gdx by gemserk.

the class AdSimulatorApplicationDelegate method render.

@Override
public void render() {
    float delta = Gdx.graphics.getRawDeltaTime();
    applicationListener.render();
    animationManager.update(delta);
    inputMonitor.update();
    if (inputMonitor.getButton("toggleAds").isReleased())
        enabled = !enabled;
    if (!enabled)
        return;
    adsVisibleMonitor.update(adMobViewSimulator.isVisible());
    AdsParameters newAdsParameters = adMobViewSimulator.getAdsParameters();
    if (newAdsParameters != adsParameters && adsVisibleMonitor.isChanged()) {
        adsParameters = newAdsParameters;
        boolean visible = adsVisibleMonitor.getValue();
        animationManager.clear();
        ArrayList<AdsAnimation> animations = adsParameters.animations;
        if (visible)
            adsColor.set(1f, 1f, 1f, 1f);
        else if (animations.size() == 0)
            adsColor.set(1f, 1f, 1f, 0f);
        for (int i = 0; i < animations.size(); i++) {
            AdsAnimation adsAnimation = animations.get(i);
            if (adsAnimation.type == Type.Alpha) {
                float[] startValue = visible ? new float[] { 0f } : new float[] { 1f };
                float[] endValue = visible ? new float[] { 1f } : new float[] { 0f };
                TimelineAnimation animation = Builders.animation(//
                Builders.timeline().value(//
                Builders.timelineValue(adsColor, //
                LibgdxConverters.colorOpacityConverter).keyFrame(0f, //
                startValue).keyFrame(((float) adsAnimation.duration) * 0.001f, //
                endValue))).speed(//
                1f).delay(//
                ((float) adsParameters.delay) * 0.001f).build();
                animation.start();
                animationManager.add(animation, new AutoRemoveAnimationHandler(animationManager), new AnimationEventHandler() {
                });
            } else if (adsAnimation.type == Type.Translation) {
                float[] startValue = visible ? new float[] { 0f, 75f } : new float[] { 0f, 0f };
                float[] endValue = visible ? new float[] { 0f, 0f } : new float[] { 0f, 75f };
                TimelineAnimation animation = Builders.animation(//
                Builders.timeline().value(//
                Builders.timelineValue(position, //
                LibgdxConverters.vector2Converter).keyFrame(0f, //
                startValue).keyFrame(((float) adsAnimation.duration) * 0.001f, //
                endValue))).speed(//
                1f).delay(//
                ((float) adsParameters.delay) * 0.001f).build();
                animation.start();
                animationManager.add(animation, new AutoRemoveAnimationHandler(animationManager), new AnimationEventHandler() {
                });
            }
        }
    }
    float cx = getCenterX(adsParameters);
    float cy = getCenterY(adsParameters);
    houseAdSprite.setColor(adsColor);
    houseAdSprite.setPosition(position.x + Gdx.graphics.getWidth() * cx - houseAdSprite.getWidth() * cx, position.y + Gdx.graphics.getHeight() * cy - houseAdSprite.getHeight() * cy);
    spriteBatch.begin();
    houseAdSprite.draw(spriteBatch);
    spriteBatch.end();
    if (houseAdSprite.getBoundingRectangle().contains(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()) && Gdx.input.justTouched()) {
        logger.info("User touched ads");
    }
}
Also used : AnimationEventHandler(com.gemserk.animation4j.animations.events.AnimationEventHandler) AdsParameters(com.gemserk.commons.admob.AdsParameters) AutoRemoveAnimationHandler(com.gemserk.animation4j.animations.events.AutoRemoveAnimationHandler) AdsAnimation(com.gemserk.commons.admob.AdsAnimation) TimelineAnimation(com.gemserk.animation4j.timeline.TimelineAnimation)

Aggregations

TimelineAnimation (com.gemserk.animation4j.timeline.TimelineAnimation)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)1 AnimationEventHandler (com.gemserk.animation4j.animations.events.AnimationEventHandler)1 AutoRemoveAnimationHandler (com.gemserk.animation4j.animations.events.AutoRemoveAnimationHandler)1 AdsAnimation (com.gemserk.commons.admob.AdsAnimation)1 AdsParameters (com.gemserk.commons.admob.AdsParameters)1