use of com.gemserk.commons.admob.AdsAnimation 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");
}
}
Aggregations