use of com.badlogic.gdx.math.Interpolation in project libgdx by libgdx.
the class InterpolationTest method create.
@Override
public void create() {
Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
renderer = new ShapeRenderer();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
stage = new Stage(new ScreenViewport());
resetPositions();
Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
// see how many fields are actually interpolations (for safety; other fields may be added with future)
int interpolationMembers = 0;
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationMembers++;
// get interpolation names
interpolationNames = new String[interpolationMembers];
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationNames[i] = interpolationFields[i].getName();
selectedInterpolation = interpolationNames[0];
list = new List(skin);
list.setItems(interpolationNames);
list.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
selectedInterpolation = list.getSelected();
time = 0;
resetPositions();
}
});
ScrollPane scroll = new ScrollPane(list, skin);
scroll.setFadeScrollBars(false);
scroll.setScrollingDisabled(true, false);
table = new Table();
table.setFillParent(true);
table.add(scroll).expandX().left().width(100);
stage.addActor(table);
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean scrolled(int amount) {
if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
return false;
duration -= amount / 15f;
duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
return true;
}
}, stage, new InputAdapter() {
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (// if "walking" was interrupted by this touch down event
!Float.isNaN(time))
// set startPosition to the current position
startPosition.set(getPosition(time));
targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
time = 0;
return true;
}
}));
}
use of com.badlogic.gdx.math.Interpolation in project libgdx by libgdx.
the class InterpolationTest method render.
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
float bottomLeftX = Gdx.graphics.getWidth() / 2 - graphSize / 2, bottomLeftY = Gdx.graphics.getHeight() / 2 - graphSize / 2;
// only show up to two decimals
String text = String.valueOf(duration);
if (text.length() > 4)
text = text.substring(0, text.lastIndexOf('.') + 3);
text = "duration: " + text + " s (ctrl + scroll to change)";
stage.getBatch().begin();
list.getStyle().font.draw(stage.getBatch(), text, bottomLeftX + graphSize / 2, bottomLeftY + graphSize + list.getStyle().font.getLineHeight(), 0, Align.center, false);
stage.getBatch().end();
renderer.begin(ShapeType.Line);
// graph bounds
renderer.rect(bottomLeftX, bottomLeftY, graphSize, graphSize);
float lastX = bottomLeftX, lastY = bottomLeftY;
for (float step = 0; step <= steps; step++) {
Interpolation interpolation = getInterpolation(selectedInterpolation);
float percent = step / steps;
float x = bottomLeftX + graphSize * percent, y = bottomLeftY + graphSize * interpolation.apply(percent);
renderer.line(lastX, lastY, x, y);
lastX = x;
lastY = y;
}
time += Gdx.graphics.getDeltaTime();
if (time > duration) {
// stop "walking"
time = Float.NaN;
// set startPosition to targetPosition for next click
startPosition.set(targetPosition);
}
// draw time marker
renderer.line(bottomLeftX + graphSize * time / duration, bottomLeftY, bottomLeftX + graphSize * time / duration, bottomLeftY + graphSize);
// draw path
renderer.setColor(Color.GRAY);
renderer.line(startPosition, targetPosition);
renderer.setColor(Color.WHITE);
renderer.end();
// draw the position
renderer.begin(ShapeType.Filled);
if (// don't mess up position if time is NaN
!Float.isNaN(time))
getPosition(time);
renderer.circle(position.x, position.y, 7);
renderer.end();
stage.act();
stage.draw();
}
use of com.badlogic.gdx.math.Interpolation in project Mindustry by Anuken.
the class PlacementFragment method toggle.
private void toggle(boolean show) {
float dur = 0.3f;
Interpolation in = Interpolation.pow3Out;
if (breaktable.getActions().size != 0 || shown == show)
return;
breaktable.getParent().swapActor(breaktable, next);
if (!show) {
control.input().breakMode = PlaceMode.none;
if (control.input().placeMode.delete)
control.input().placeMode = PlaceMode.none;
breaktable.actions(Actions.translateBy(-breaktable.getWidth() - 5, 0, dur, in), Actions.call(() -> shown = false));
} else {
shown = true;
breaktable.actions(Actions.translateBy(-breaktable.getTranslation().x - 5, 0, dur, in));
}
}
use of com.badlogic.gdx.math.Interpolation in project Mindustry by Anuken.
the class Shield method update.
@Override
public void update() {
float alpha = 0.1f;
Interpolation interp = Interpolation.fade;
if (active) {
uptime = interp.apply(uptime, 1f, alpha * Timers.delta());
} else {
uptime = interp.apply(uptime, 0f, alpha * Timers.delta());
if (uptime <= 0.05f)
remove();
}
uptime = Mathf.clamp(uptime);
if (!(tile.block() instanceof ShieldBlock)) {
remove();
return;
}
ShieldBlock block = (ShieldBlock) tile.block();
Entities.getNearby(bulletGroup, x, y, block.shieldRadius * 2 * uptime + 10, entity -> {
BulletEntity bullet = (BulletEntity) entity;
if ((bullet.owner instanceof Enemy || hitPlayers)) {
float dst = entity.distanceTo(this);
if (dst < drawRadius() / 2f) {
((ShieldBlock) tile.block()).handleBullet(tile, bullet);
}
}
});
}
use of com.badlogic.gdx.math.Interpolation in project Mindustry by Anuken.
the class HudFragment method build.
public void build() {
// menu at top left
new table() {
{
atop();
aleft();
new table() {
{
new table() {
{
left();
float dsize = 58;
defaults().size(dsize).left();
float isize = 40;
menu = new imagebutton("icon-menu", isize, ui.paused::show).get();
flip = new imagebutton("icon-arrow-up", isize, () -> {
if (wavetable.getActions().size != 0)
return;
float dur = 0.3f;
Interpolation in = Interpolation.pow3Out;
flip.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up");
if (shown) {
blockfrag.toggle(false, dur, in);
wavetable.actions(Actions.translateBy(0, wavetable.getHeight() + dsize, dur, in), Actions.call(() -> shown = false));
infolabel.actions(Actions.translateBy(0, wavetable.getHeight(), dur, in), Actions.call(() -> shown = false));
} else {
shown = true;
blockfrag.toggle(true, dur, in);
wavetable.actions(Actions.translateBy(0, -wavetable.getTranslation().y, dur, in));
infolabel.actions(Actions.translateBy(0, -infolabel.getTranslation().y, dur, in));
}
}).get();
new imagebutton("icon-pause", isize, () -> {
if (android)
DebugFragment.printDebugInfo();
if (Net.active() && android) {
ui.listfrag.visible = !ui.listfrag.visible;
} else {
state.set(state.is(State.paused) ? State.playing : State.paused);
}
}).update(i -> {
if (Net.active() && android) {
i.getStyle().imageUp = Core.skin.getDrawable("icon-players");
} else {
i.setDisabled(Net.active());
i.getStyle().imageUp = Core.skin.getDrawable(state.is(State.paused) ? "icon-play" : "icon-pause");
}
}).get();
new imagebutton("icon-settings", isize, () -> {
if (Net.active() && android) {
if (ui.chatfrag.chatOpen()) {
ui.chatfrag.hide();
} else {
ui.chatfrag.toggle();
}
} else {
ui.settings.show();
}
}).update(i -> {
if (Net.active() && android) {
i.getStyle().imageUp = Core.skin.getDrawable("icon-chat");
} else {
i.getStyle().imageUp = Core.skin.getDrawable("icon-settings");
}
}).get();
}
}.end();
row();
new table() {
{
touchable(Touchable.enabled);
visible(() -> shown);
addWaveTable();
}
}.fillX().end();
row();
visible(() -> !state.is(State.menu));
infolabel = new Label(() -> (Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") + (threads.isEnabled() ? " / " + threads.getFPS() + " TPS" : "") + (Net.client() && !gwt ? "\nPing: " + Net.getPing() : "") : ""));
row();
add(infolabel).size(-1);
}
}.end();
}
}.end();
// tutorial ui table
new table() {
{
control.tutorial().buildUI(this);
visible(() -> control.tutorial().active());
}
}.end();
// paused table
new table() {
{
visible(() -> state.is(State.paused) && !Net.active());
atop();
new table("pane") {
{
new label("[orange]< " + Bundles.get("text.paused") + " >").scale(0.75f).pad(6);
}
}.end();
}
}.end();
// respawn background table
new table("white") {
{
respawntable = get();
respawntable.setColor(Color.CLEAR);
update(t -> {
if (state.is(State.menu)) {
respawntable.setColor(Color.CLEAR);
}
});
}
}.end();
// respawn table
new table() {
{
new table("pane") {
{
new label(() -> "[orange]" + Bundles.get("text.respawn") + " " + (int) (control.getRespawnTime() / 60)).scale(0.75f).pad(10);
visible(() -> control.getRespawnTime() > 0 && !state.is(State.menu));
}
}.end();
}
}.end();
new table() {
{
abottom();
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
new label("$text.saveload");
}
}.end();
blockfrag.build();
}
Aggregations