Java Code Examples for com.badlogic.gdx.utils.TimeUtils

The following examples show how to use com.badlogic.gdx.utils.TimeUtils. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: uracer-kotd   Source File: Input.java    License: Apache License 2.0 6 votes vote down vote up
private void updateRepeated () {
	for (int i = 0; i < buttons.length; i++) {
		if (isOn(i)) {
			long now = TimeUtils.nanoTime();
			if (!repeated[i]) {
				long comparens = first_repeat[i] ? firstrepeatns : repeatns;
				if (times[i] == -1) times[i] = now;
				if (now - times[i] > comparens) {
					repeated[i] = true;
					times[i] = now;
					first_repeat[i] = false;
				}
			} else {
				repeated[i] = false;
			}
		} else {
			repeated[i] = false;
			times[i] = -1;
			first_repeat[i] = true;
		}
	}
}
 
Example 2
public boolean getNegativeState() {
	if (Gdx.input.getDeltaX() < 0 || Gdx.input.getDeltaY() < 0) {
		// Triggered negative scratch
		// Update trigger time
		Gdx.input.setCursorPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
		negative_last_time = TimeUtils.millis();
		return true;
	} else {
		long current = TimeUtils.millis();
		long different = current - negative_last_time;
		if (negative_last_time < positive_last_time) // Check latest scratch state
			return false;
		else
			return different < scratchDuration; // Check timeout
	}
}
 
Example 3
Source Project: collider   Source File: Demos.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void render() {
	long time = TimeUtils.nanoTime();
	if(clicked) {
		clicked = false;
		scenarioI = (scenarioI + 1) % Scenarios.NUM_SCENARIOS;
		Scenarios.initScenario(scenarioI);
		startTime = time;
	}
	Game.engine.stepToTime((TimeUtils.nanoTime() - startTime)*1e-9);
	
	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	
	Game.engine.render(true);
}
 
Example 4
Source Project: ud406   Source File: RectangleCircleCollisionScreen.java    License: MIT License 6 votes vote down vote up
public RectangleCircleCollisionScreen() {
    startTime = TimeUtils.nanoTime();
    shapeRenderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    rectangles = new Array<Rectangle>(new Rectangle[]{
            new Rectangle(40, 40, 20, 20), // Middle
            new Rectangle(10, 40, 10, 20), // Left
            new Rectangle(70, 45, 20, 10) // Right
    });

    circles = new Array<OscillatingCircle>(new OscillatingCircle[]{
            new OscillatingCircle(50, 65, 7, 0, 40, 3), // High horizontal
            new OscillatingCircle(50, 35, 7, 0, 40, 3.1f), // Low horizontal
            new OscillatingCircle(50, 50, 3, MathUtils.PI / 4, 40, 5f), // Diagonal
            new OscillatingCircle(25, 50, 5, 0, 11, 7f), // Middle horizontal
    });
}
 
Example 5
Source Project: ud405   Source File: OrthographicCameraExercise.java    License: MIT License 6 votes vote down vote up
@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // TODO: Call update() on the camera


    // TODO: Set the SceneRenderer's projection matrix equal to the camera's combined matrix


    renderer.begin(ShapeType.Filled);
    float interval = TimeUtils.timeSinceMillis(timeCreated);
    float x = X_CENTER + X_AMPLITUDE * MathUtils.sin(MathUtils.PI2 * interval /PERIOD);
    float y = Y_CENTER + Y_AMPLITUDE * MathUtils.sin(2* MathUtils.PI2 * interval / PERIOD);
    renderer.circle(x, y, BALL_RADIUS);
    renderer.end();
}
 
Example 6
Source Project: buffer_bci   Source File: VisSpeller.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void bufferRetry() {
	if (startOfState) {
		lastStateTime = TimeUtils.millis();
		startOfState = false;
	}
	retryingText.draw();
	if (TimeUtils.millis() - lastStateTime > TIME_RETRY_CLIENT) {
		try {
			 if ( !ftc.isConnected() ) {
				  ftc.connect(adress, port);
			 }
			Header hdr = ftc.getHeader();
			nSamples = hdr.nSamples;
			fSample = hdr.fSample;
			lastUpdate = TimeUtils.millis();
			nextState();
		} catch (IOException e) {
			System.out.println(e.getMessage());
			if (e.getMessage().endsWith("517")) {
				changeState(States.WAITING_FOR_HEADER);
			} else {
				lastStateTime = TimeUtils.millis();
			}
		}
	}
}
 
Example 7
Source Project: FruitCatcher   Source File: Button.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isPressed(Vector3 touchPos) {
       float x = touchPos.x;
       float y = touchPos.y;		
	if (x > startX && x < endX && y > startY && y < endY) {
		long now = TimeUtils.millis();
		if (now - timePressed > 200) {
			timePressed  = TimeUtils.millis();
			return true;
		}
	}
	return false;
}
 
Example 8
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 9
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 10
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 11
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 12
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveLeft(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.LEFT;
    position.x -= delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 13
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveLeft(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.LEFT;
    position.x -= delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 14
Source Project: ud406   Source File: Enemy.java    License: MIT License 5 votes vote down vote up
public Enemy(Platform platform) {
    this.platform = platform;
    direction = Direction.RIGHT;
    position = new Vector2(platform.left, platform.top + Constants.ENEMY_CENTER.y);
    startTime = TimeUtils.nanoTime();
    health = Constants.ENEMY_HEALTH;
}
 
Example 15
Source Project: ud406   Source File: Enemy.java    License: MIT License 5 votes vote down vote up
public Enemy(Platform platform) {
    this.platform = platform;
    direction = Direction.RIGHT;
    position = new Vector2(platform.left, platform.top + Constants.ENEMY_CENTER.y);
    startTime = TimeUtils.nanoTime();
    health = Constants.ENEMY_HEALTH;
}
 
Example 16
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 17
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void continueJump() {
    if (jumpState == JumpState.JUMPING) {
        float jumpDuration = MathUtils.nanoToSec * (TimeUtils.nanoTime() - jumpStartTime);
        if (jumpDuration < Constants.MAX_JUMP_DURATION) {
            velocity.y = Constants.JUMP_SPEED;
        } else {
            endJump();
        }
    }
}
 
Example 18
Source Project: ud406   Source File: GameplayScreen.java    License: MIT License 5 votes vote down vote up
private void renderLevelEndOverlays(SpriteBatch batch) {
    if (level.gameOver) {

        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            gameOverOverlay.init();
        }

        gameOverOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelFailed();
        }
    } else if (level.victory) {
        if (levelEndOverlayStartTime == 0) {
            levelEndOverlayStartTime = TimeUtils.nanoTime();
            victoryOverlay.init();
        }

        victoryOverlay.render(batch);
        if (Utils.secondsSince(levelEndOverlayStartTime) > Constants.LEVEL_END_DURATION) {
            levelEndOverlayStartTime = 0;
            levelComplete();
        }

    }
}
 
Example 19
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 20
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void continueJump() {
    if (jumpState == JumpState.JUMPING) {
        float jumpDuration = MathUtils.nanoToSec * (TimeUtils.nanoTime() - jumpStartTime);
        if (jumpDuration < Constants.MAX_JUMP_DURATION) {
            velocity.y = Constants.JUMP_SPEED;
        } else {
            endJump();
        }
    }
}
 
Example 21
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveLeft(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.LEFT;
    position.x -= delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 22
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveLeft(float delta) {
    if (jumpState == JumpState.GROUNDED && walkState != WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = WalkState.WALKING;
    facing = Facing.LEFT;
    position.x -= delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 23
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveLeft(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.LEFT;
    position.x -= delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 24
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void continueJump() {
    if (jumpState == JumpState.JUMPING) {
        float jumpDuration = MathUtils.nanoToSec * (TimeUtils.nanoTime() - jumpStartTime);
        if (jumpDuration < Constants.MAX_JUMP_DURATION) {
            velocity.y = Constants.JUMP_SPEED;
        } else {
            endJump();
        }
    }
}
 
Example 25
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 26
Source Project: ud406   Source File: GigaGal.java    License: MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == Enums.JumpState.GROUNDED && walkState != Enums.WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = Enums.WalkState.WALKING;
    facing = Direction.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 27
Source Project: shattered-pixel-dungeon   Source File: Game.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void update() {
	Game.elapsed = Game.timeScale * Gdx.graphics.getDeltaTime();
	Game.timeTotal += Game.elapsed;
	
	Game.realTime = TimeUtils.millis();

	inputHandler.processAllEvents();
	
	scene.update();
	Camera.updateAll();
}
 
Example 28
Source Project: gdx-facebook   Source File: HTMLGDXFacebook.java    License: Apache License 2.0 5 votes vote down vote up
private void silentLogin(final Array<String> permissions, final GDXFacebookCallback<SignInResult> callback) {
        Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting silent sign in.");

        signOut(false);

        JSNIFacebookSDK.FBLoginState(new StatusCallback() {
            @Override
            public void connected(String token, String expiresIn) {
                isConnected = true;
                long expiresInMillisFromNow = Long.valueOf(expiresIn) * 1000L;
                long expiresInMillisTimestamp = expiresInMillisFromNow + TimeUtils.millis();
                accessToken = new GDXFacebookAccessToken(token, expiresInMillisTimestamp);
                storeToken(accessToken);
//                callback.onSuccess(new SignInResult(accessToken, "Silently logged in. AccessToken and permissions are valid."));
                validatePermissions(permissions, callback);
            }

            @Override
            public void notAuthorized() {
                guiLogin(permissions, callback);
            }

            @Override
            public void disconnected() {
                guiLogin(permissions, callback);
            }
        });
    }
 
Example 29
Source Project: gdx-facebook   Source File: HTMLGDXFacebook.java    License: Apache License 2.0 5 votes vote down vote up
private void guiLogin(final Array<String> permissions, final GDXFacebookCallback<SignInResult> callback) {
    signOut(false);

    Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Start GUI login.");
    // GUI LOGIN
    JSNIFacebookSDK.FBLogin(permissionsArrayToString(permissions), new LoginCallback() {

        @Override
        public void success(String token, String expiresIn, String gPermissions) {
            Gdx.app.debug(GDXFacebookVars.LOG_TAG, "success granted: " + gPermissions);

            String[] parts = gPermissions.split(",");

            grantedPermissions.clear();

            for (String s : parts) {
                grantedPermissions.add(s);
            }

            if (areSamePermissionsOrMore(permissions, grantedPermissions)) {
                isConnected = true;
                long expiresInMillisFromNow = Long.valueOf(expiresIn) * 1000L;
                long expiresInMillisTimestamp = expiresInMillisFromNow + TimeUtils.millis();
                accessToken = new GDXFacebookAccessToken(token, expiresInMillisTimestamp);
                storeToken(accessToken);
                callback.onSuccess(new SignInResult(accessToken, "Login successful. AccessToken and permissions are valid."));
            } else {
                callback.onError(new GDXFacebookError("User did not grant required permissions."));
            }


        }

        @Override
        public void fail() {
            callback.onError(new GDXFacebookError("Error while trying to login. User cancelled or did not authorize."));
        }

    });
}
 
Example 30
Source Project: riiablo   Source File: PacketTuple.java    License: Apache License 2.0 5 votes vote down vote up
public static PacketTuple obtain(int id, ByteBuffer buffer) {
  PacketTuple packet = new PacketTuple();
  packet.id = id;
  packet.time = TimeUtils.millis();
  packet.buffer = buffer;
  packet.data = Netty.getRootAsNetty(buffer);
  return packet;
}