Search in sources :

Example 1 with Timer

use of com.badlogic.gdx.utils.Timer 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 Timer

use of com.badlogic.gdx.utils.Timer in project Alkahest-Coffee by AlkahestDev.

the class MainMenu method init.

/*public void draw(SpriteBatch sb, ShapeRenderer sr) {
        super.draw(sb, sr);
        sb.begin();
            this.spriteDraw(sb);
        sb.end();
        sr.begin(ShapeRenderer.ShapeType.Filled);
            this.shapeDraw(sr);
        sr.end();
        sb.begin();
            this.fontDraw(sb);
        sb.end();
    }*/
public void init() {
    this.setBackground(new TextureRegion((Texture) super.getManager().get("4914003-galaxy-wallpaper-png.png")));
    final MenuBox askUserNameBox = new MenuBox(Gdx.graphics.getWidth() / 2 - 180, Gdx.graphics.getHeight() / 2 - 70, 360, 140, super.getFonts());
    final MenuTools.TextField askUserNameField = new MenuTools.TextField(5, 5, 350, 40);
    final MenuTools.QueueText userNameError = new MenuTools.QueueText(5, 60, 0, 0);
    askUserNameField.setEnterAction(new MenuTools.OnEnter() {

        @Override
        public void action(String sIn) {
            int gHeight = Gdx.graphics.getHeight();
            if (sIn.contains(" ")) {
                // prevents the previous timer from clearing this text prematurely
                Timer.instance().clear();
                userNameError.setText("[RED]Username cannot contain spaces!", MainMenu.super.getFonts());
                Timer.schedule(new Timer.Task() {

                    @Override
                    public void run() {
                        userNameError.clearText();
                    }
                }, 2);
            } else if (sIn.length() == 0) {
                // prevents the previous timer from clearing this text prematurely
                Timer.instance().clear();
                userNameError.setText("[RED]Username cannot be empty!", MainMenu.super.getFonts());
                Timer.schedule(new Timer.Task() {

                    @Override
                    public void run() {
                        userNameError.clearText();
                    }
                }, 2);
            } else {
                float vY = -18.4f;
                if (gHeight >= 660) {
                    vY = -(20f + (gHeight - 660) / 60f);
                }
                askUserNameBox.setVelocity(0, vY);
                //askUserNameBox.moveTo(950,-20);
                askUserNameField.setEnterAction(new MenuTools.OnEnter() {

                    public void action(String sIn) {
                    }
                });
                // set the action to do nothing so you can't reset the velocity
                // At the current state you can use colourmarkup to change the colour of your username. I'm keeping this in because it looks cool
                MainGame.clientSoldier.setName(sIn);
                //I might have to remove the ColourMarkup if it messes with calculating lengths of things
                System.out.println("Username: " + sIn);
                addMenuButtons();
            }
        }
    });
    userNameError.setFont(DAGGER20);
    askUserNameBox.addQueueText(userNameError);
    askUserNameBox.addTextField(askUserNameField);
    askUserNameBox.setBackground(new TextureRegion((Texture) super.getManager().get("menubackdrops/canvas.png")));
    String tempMessage = "Enter a username";
    MenuTools.QueueText tempQt = new MenuTools.QueueText(180 - MenuTools.textWidth(super.getFonts().get(DAGGER40).getFont(), tempMessage) / 2, 120, 0, 0);
    tempQt.setText(tempMessage, super.getFonts());
    askUserNameBox.addQueueText(tempQt);
    super.addMenuBox(askUserNameBox);
}
Also used : MenuTools(me.dumfing.gdxtools.MenuTools) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Timer(com.badlogic.gdx.utils.Timer)

Aggregations

Timer (com.badlogic.gdx.utils.Timer)2 Texture (com.badlogic.gdx.graphics.Texture)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Task (com.badlogic.gdx.utils.Timer.Task)1 MenuTools (me.dumfing.gdxtools.MenuTools)1