Search in sources :

Example 1 with Task

use of com.badlogic.gdx.utils.Timer.Task in project libgdx by libgdx.

the class TimerTest method create.

@Override
public void create() {
    Timer timer = new Timer();
    Task task = timer.scheduleTask(new Task() {

        @Override
        public void run() {
            Gdx.app.log("TimerTest", "ping");
        }
    }, 1, 1);
    Gdx.app.log("TimerTest", "is task scheduled: " + String.valueOf(task.isScheduled()));
}
Also used : Task(com.badlogic.gdx.utils.Timer.Task) Timer(com.badlogic.gdx.utils.Timer)

Example 2 with Task

use of com.badlogic.gdx.utils.Timer.Task in project libgdx by libgdx.

the class NoncontinuousRenderingTest method populateTable.

private void populateTable() {
    Table root = new Table();
    stage.addActor(root);
    root.setFillParent(true);
    root.pad(5);
    root.defaults().left().space(5);
    Button button0 = new TextButton("Toggle continuous rendering", skin, "toggle");
    button0.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            boolean continuous = Gdx.graphics.isContinuousRendering();
            Gdx.graphics.setContinuousRendering(!continuous);
        }
    });
    root.add(button0).row();
    final String str1 = "2s sleep -> Application.postRunnable()";
    Button button1 = new TextButton(str1, skin);
    button1.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            new Thread(new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                    nextColor();
                    Gdx.app.postRunnable(new Runnable() {

                        public void run() {
                            Gdx.app.log(str1, "Posted runnable to Gdx.app");
                        }
                    });
                }
            }).start();
        }
    });
    root.add(button1).row();
    final String str2 = "2s sleep -> Graphics.requestRendering()";
    Button button2 = new TextButton(str2, skin);
    button2.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            // caching necessary to ensure call on this window
            final Graphics graphics = Gdx.graphics;
            new Thread(new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ignored) {
                    }
                    nextColor();
                    graphics.requestRendering();
                    Gdx.app.log(str2, "Called Gdx.graphics.requestRendering()");
                }
            }).start();
        }
    });
    root.add(button2).row();
    final String str3 = "2s Timer -> Application.postRunnable()";
    Button button3 = new TextButton(str3, skin);
    button3.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Timer.schedule(new Task() {

                public void run() {
                    nextColor();
                    Gdx.app.postRunnable(new Runnable() {

                        public void run() {
                            Gdx.app.log(str3, "Posted runnable to Gdx.app");
                        }
                    });
                }
            }, 2f);
        }
    });
    root.add(button3).row();
    final String str4 = "2s DelayAction";
    Button button4 = new TextButton(str4, skin);
    button4.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            stage.addAction(Actions.sequence(Actions.delay(2), Actions.run(new Runnable() {

                public void run() {
                    nextColor();
                    Gdx.app.log(str4, "RunnableAction executed");
                }
            })));
        }
    });
    root.add(button4).row();
    final String str5 = "(2s sleep -> toggle continuous) 2X";
    Button button5 = new TextButton(str5, skin);
    button5.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            // caching necessary to ensure call on this window
            final Graphics graphics = Gdx.graphics;
            new Thread(new Runnable() {

                public void run() {
                    for (int i = 0; i < 2; i++) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException ignored) {
                        }
                        nextColor();
                        boolean continuous = graphics.isContinuousRendering();
                        graphics.setContinuousRendering(!continuous);
                        Gdx.app.log(str5, "Toggled continuous");
                    }
                }
            }).start();
        }
    });
    root.add(button5).row();
    final CheckBox actionsRequestRendering = new CheckBox("ActionsRequestRendering", skin);
    actionsRequestRendering.setChecked(true);
    actionsRequestRendering.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            stage.setActionsRequestRendering(actionsRequestRendering.isChecked());
        }
    });
    root.add(actionsRequestRendering).row();
    Drawable knobDown = skin.newDrawable("default-slider-knob", Color.GRAY);
    SliderStyle sliderStyle = skin.get("default-horizontal", SliderStyle.class);
    sliderStyle.knobDown = knobDown;
    Slider slider = new Slider(0, 100, 1, false, sliderStyle);
    root.add(slider).row();
    SelectBox<Pixmap.Format> selectBox = new SelectBox(skin);
    selectBox.setItems(Pixmap.Format.values());
    root.add(selectBox).row();
    root.add();
    root.add().grow();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Task(com.badlogic.gdx.utils.Timer.Task) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Graphics(com.badlogic.gdx.Graphics) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) SliderStyle(com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle)

Example 3 with Task

use of com.badlogic.gdx.utils.Timer.Task in project gdx-skineditor by cobolfoo.

the class Tooltips method hideTooltip.

public void hideTooltip() {
    if (tooltip != null) {
        tooltip.remove();
        if (hide == null || !hide.isScheduled()) {
            hide = new Task() {

                @Override
                public void run() {
                    if (tooltip != null) {
                        tooltip = null;
                    }
                }
            };
            Timer.schedule(hide, 1);
        }
    }
}
Also used : Task(com.badlogic.gdx.utils.Timer.Task)

Aggregations

Task (com.badlogic.gdx.utils.Timer.Task)3 Graphics (com.badlogic.gdx.Graphics)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)1 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)1 SliderStyle (com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1 Timer (com.badlogic.gdx.utils.Timer)1