Java Code Examples for com.badlogic.gdx.utils.Timer#schedule()

The following examples show how to use com.badlogic.gdx.utils.Timer#schedule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameJoltClient.java    From gdx-gamesvcs with Apache License 2.0 6 votes vote down vote up
protected void sendOpenSessionEvent() {
    if (!isSessionActive())
        return;

    Map<String, String> params = new HashMap<String, String>();
    addGameIDUserNameUserToken(params);

    final Net.HttpRequest http = buildJsonRequest("sessions/open/", params);

    if (http != null)
        Gdx.net.sendHttpRequest(http, new NoOpResponseListener());

    pingTask = Timer.schedule(new Timer.Task() {
        @Override
        public void run() {
            sendKeepSessionOpenEvent();
        }
    }, GJ_PING_INTERVAL, GJ_PING_INTERVAL);

}
 
Example 2
Source File: Tooltip.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) {
	if (pointer == -1) {
		Vector2 targetPos = target.localToStageCoordinates(new Vector2());

		setX(targetPos.x + (target.getWidth() - getWidth()) / 2);

		float tooltipY = targetPos.y - getHeight() - 6;
		float stageHeight = target.getStage().getHeight();

		//is there enough space to display above widget?
		if (stageHeight - tooltipY > stageHeight)
			setY(targetPos.y + target.getHeight() + 6); //display above widget
		else
			setY(tooltipY); //display below

		displayTask.cancel();
		Timer.schedule(displayTask, appearDelayTime);
	}
}
 
Example 3
Source File: CreateProjectDialog.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void ok() {
	try {
		Ctx.project.getEditorConfig().setProperty(ANDROID_SDK_PROP, androidSdk.getText());
		Ctx.project.saveProject();
	} catch (Exception ex) {
		String msg = ex.getClass().getSimpleName()
				+ " - " + ex.getMessage();
		Message.showMsgDialog(getStage(), "Error saving project", msg);
	}
	
	final Stage stage = getStage();

	Message.showMsg(getStage(), "Creating project...", true);
	Timer.schedule(new Task() {
		@Override
		public void run() {
			createProject(stage);
		}
	},1);
}
 
Example 4
Source File: CreateResolutionDialog.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void ok() {

	final Stage stage = getStage();

	Message.showMsg(stage, "Creating resolution...", true);

	Timer.schedule(new Task() {
		@Override
		public void run() {
			createResolution();

			String msg = scaleImages();

			if (listener != null)
				listener.changed(new ChangeEvent(), CreateResolutionDialog.this);

			Message.hideMsg();

			if (msg != null)
				Message.showMsgDialog(stage, "Error creating resolution", msg);
		}
	}, 1);
}
 
Example 5
Source File: GpgsClient.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
protected void onInitialized() {
    initialized = true;
    connectionPending = false;
    // if Google API has initialized, check if user session is active
    displayName = "";
    boolean sessionActive = isSessionActive();

    if (updateEventsTask != null)
        updateEventsTask.cancel();

    if (sessionActive) {
        oAuthToken = getOAuthToken();
        sendNowPlayingEvent();
        refreshDisplayname();
        updateEventsTask = Timer.schedule(new Timer.Task() {
            @Override
            public void run() {
                recordEvents();
            }
        }, GPGS_CHECKEVENTS_INTERVAL, GPGS_CHECKEVENTS_INTERVAL);
    }

    if (gsListener != null) {
        if (sessionActive)
            gsListener.gsOnSessionActive();
        else
            gsListener.gsOnSessionInactive();
    }
}
 
Example 6
Source File: MockGameServiceClient.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
private void sleep(final Runnable runnable) {
    if (runnable != null)
        Timer.schedule(new Timer.Task() {
            @Override
            public void run() {
                runnable.run();
            }
        }, latency);
}
 
Example 7
Source File: BadlogicTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void action() {
    img = new Texture("badlogic.jpg");
    Timer.schedule(new Timer.Task() {
        @Override
        public void run() {
            success();
        }
    }, 1f);
}
 
Example 8
Source File: DatabaseListenerValueTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void action() {
    GdxFIRDatabase.instance()
            .inReference("/test-listen-value")
            .onDataChange(String.class)
            .after(GdxFIRAuth.instance().signInAnonymously())
            .then(new Consumer<String>() {
                @Override
                public void accept(String s) {
                    Gdx.app.log("App", "new value: " + s);
                    listenCounter.incrementAndGet();
                }
            });
    scheduler = Timer.schedule(new Timer.Task() {
        @Override
        public void run() {
            Gdx.app.log("App", "set new value");
            GdxFIRDatabase.instance()
                    .inReference("/test-listen-value")
                    .setValue("abc" + Math.random())
                    .after(GdxFIRAuth.instance().signInAnonymously())
                    .subscribe();

            if (counter.incrementAndGet() >= 4) {
                if (listenCounter.get() >= 3) {
                    scheduler.cancel();
                    success();
                }
            }
        }
    }, 0.3f, 0.6f);
}
 
Example 9
Source File: ToastManager.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Displays toast. Toast will be displayed for given amount of seconds. */
public Toast show (final Toast toast, float timeSec) {
	Table toastMainTable = toast.getMainTable();
	if (toastMainTable.getStage() != null) {
		remove(toast);
	}
	toasts.add(toast);

	toast.setToastManager(this);
	toast.fadeIn();
	toastMainTable.pack();
	root.addActor(toastMainTable);

	updateToastsPositions();

	if (timeSec > 0) {
		Timer.Task fadeOutTask = new Timer.Task() {
			@Override
			public void run () {
				toast.fadeOut();
				timersTasks.remove(toast);
			}
		};
		timersTasks.put(toast, fadeOutTask);
		Timer.schedule(fadeOutTask, timeSec);
	}
	return toast;
}
 
Example 10
Source File: ToastManager.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/** Displays toast. Toast will be displayed for given amount of seconds. */
public void show (final Toast toast, float timeSec) {
	Table toastMainTable = toast.getMainTable();
	if (toastMainTable.getStage() != null) {
		remove(toast);
	}
	toasts.add(toast);

	toast.setToastManager(this);
	toast.fadeIn();
	toastMainTable.pack();
	root.addActor(toastMainTable);

	updateToastsPositions();

	if (timeSec > 0) {
		Timer.Task fadeOutTask = new Timer.Task() {
			@Override
			public void run () {
				toast.fadeOut();
				timersTasks.remove(toast);
			}
		};
		timersTasks.put(toast, fadeOutTask);
		Timer.schedule(fadeOutTask, timeSec);
	}
}
 
Example 11
Source File: Spinner.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
	if (buttonRepeatTask.isScheduled() == false) {
		buttonRepeatTask.advance = advance;
		buttonRepeatTask.cancel();
		Timer.schedule(buttonRepeatTask, buttonRepeatInitialTime, buttonRepeatTime);
	}
	return true;
}
 
Example 12
Source File: VoiceManager.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void play(String fileName) {
	stop();

	this.fileName = fileName;

	if (fileName != null) {
		// Load and play the voice file in background to avoid
		// blocking the UI
		loadAssets();

		backgroundLoadingTask.cancel();
		Timer.schedule(backgroundLoadingTask, 0, 0);
	}
}
 
Example 13
Source File: CreateAtlasDialog.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void ok() {
	Message.showMsg(getStage(), "Generating atlas...", true);

	Timer.schedule(new Task() {
		@Override
		public void run() {
			genAtlas();
		}
	}, 1);
}
 
Example 14
Source File: RenderedConsole.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void updateCaret() {
  caretBlinkTask.cancel();
  Timer.schedule(caretBlinkTask, CARET_HOLD_DELAY, CARET_BLINK_DELAY);
  showCaret = true;
}
 
Example 15
Source File: MusicManager.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
private void loadTask() {
	loadAssets();

	backgroundLoadingTask.cancel();
	Timer.schedule(backgroundLoadingTask, 0, 0);
}