Java Code Examples for com.badlogic.gdx.utils.TimeUtils#nanoTime()

The following examples show how to use com.badlogic.gdx.utils.TimeUtils#nanoTime() . 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: GigaGal.java    From ud406 with 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 2
Source File: GameplayScreen.java    From ud406 with 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 3
Source File: GigaGal.java    From ud406 with 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 4
Source File: GigaGal.java    From ud406 with MIT License 5 votes vote down vote up
private void startJump() {
    // TODO: Set jumpState to JUMPING
    jumpState = JumpState.JUMPING;
    // TODO: Set the jump start time
    // Using TimeUtils.nanoTime()
    jumpStartTime = TimeUtils.nanoTime();
    // TODO: Call continueJump()
    continueJump();
}
 
Example 5
Source File: GigaGal.java    From ud406 with 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 6
Source File: Enemy.java    From ud406 with 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;
    bobOffset = MathUtils.random();
}
 
Example 7
Source File: GigaGal.java    From ud406 with 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 8
Source File: GameplayScreen.java    From ud406 with 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 9
Source File: GigaGal.java    From ud406 with MIT License 5 votes vote down vote up
private void moveRight(float delta) {
    if (jumpState == JumpState.GROUNDED && walkState != WalkState.WALKING) {
        walkStartTime = TimeUtils.nanoTime();
    }
    walkState = WalkState.WALKING;
    facing = Facing.RIGHT;
    position.x += delta * Constants.GIGAGAL_MOVE_SPEED;
}
 
Example 10
Source File: GigaGal.java    From ud406 with 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 File: Utils.java    From ud406 with MIT License 4 votes vote down vote up
public static float secondsSince(long timeNanos) {
    return MathUtils.nanoToSec * (TimeUtils.nanoTime() - timeNanos);
}
 
Example 12
Source File: GigaGal.java    From ud406 with MIT License 4 votes vote down vote up
private void startJump() {
    jumpState = JumpState.JUMPING;
    jumpStartTime = TimeUtils.nanoTime();
    continueJump();
}
 
Example 13
Source File: Enemy.java    From ud406 with MIT License 4 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();
}
 
Example 14
Source File: Utils.java    From ud406 with MIT License 4 votes vote down vote up
public static float secondsSince(long timeNanos) {
    return MathUtils.nanoToSec * (TimeUtils.nanoTime() - timeNanos);
}
 
Example 15
Source File: Utils.java    From ud406 with MIT License 4 votes vote down vote up
public static float secondsSince(long timeNanos) {
    return MathUtils.nanoToSec * (TimeUtils.nanoTime() - timeNanos);
}
 
Example 16
Source File: PreviewWidget.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void drawContent(Batch batch, float parentAlpha) {
    batch.end();
    drawGrid(batch, parentAlpha * 0.5f);
    batch.begin();

    mid.set(0, 0);

    float imagePrefWidth = previewImage.getPrefWidth();
    float imagePrefHeight = previewImage.getPrefHeight();
    float scale = imagePrefHeight / imagePrefWidth;

    float imageWidth = previewController.getImageWidth();
    float imageHeight = imageWidth * scale;
    previewController.getPreviewBoxWidth();

    previewImage.setPosition(mid.x - imageWidth / 2, mid.y - imageHeight / 2);
    previewImage.setSize(imageWidth, imageHeight);
    if (previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    spriteBatchParticleRenderer.setBatch(batch);

    batch.flush();
    glProfiler.enable();

    long timeBefore = TimeUtils.nanoTime();

    final ParticleEffectInstance particleEffect = TalosMain.Instance().TalosProject().getParticleEffect();
    particleEffect.render(particleRenderer);

    batch.flush();
    renderTime.put(TimeUtils.timeSinceNanos(timeBefore));
    trisCount = (int) (glProfiler.getVertexCount().value / 3f);
    glProfiler.disable();


    if (!previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    // now for the drag points
    if(dragPoints.size > 0) {
        batch.end();
        tmpColor.set(Color.ORANGE);
        tmpColor.a = 0.8f;
        Gdx.gl.glLineWidth(1f);
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
        shapeRenderer.setColor(tmpColor);

        for (DragPoint point : dragPoints) {
            shapeRenderer.circle(point.position.x, point.position.y, 0.1f * camera.zoom, 15);
        }

        shapeRenderer.end();
        batch.begin();
    }
}
 
Example 17
Source File: Enemy.java    From ud406 with MIT License 4 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();
}
 
Example 18
Source File: Utils.java    From ud406 with MIT License 4 votes vote down vote up
public static float secondsSince(long timeNanos) {
    return MathUtils.nanoToSec * (TimeUtils.nanoTime() - timeNanos);
}
 
Example 19
Source File: PathSmoother.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
/** Smoothes in place the path specified by the given request, possibly over multiple consecutive frames.
 * @param request the path smoothing request
 * @param timeToRun the time in nanoseconds that this call can use on the current frame
 * @return {@code true} if this operation has completed; {@code false} if more time is needed to complete. */
public boolean smoothPath (PathSmootherRequest<N, V> request, long timeToRun) {

	long lastTime = TimeUtils.nanoTime();

	SmoothableGraphPath<N, V> path = request.path;
	int inputPathLength = path.getCount();

	// If the path is two nodes long or less, then we can't smooth it
	if (inputPathLength <= 2) return true;

	if (request.isNew) {
		request.isNew = false;

		// Make sure the ray is instantiated
		if (this.ray == null) {
			V vec = request.path.getNodePosition(0);
			this.ray = new Ray<V>(vec.cpy(), vec.cpy());
		}

		// Keep track of where we are in the smoothed path.
		// We start at 1, because we must always include the start node in the smoothed path.
		request.outputIndex = 1;

		// Keep track of where we are in the input path
		// We start at 2, because we assume two adjacent
		// nodes will pass the ray cast
		request.inputIndex = 2;

	}

	// Loop until we find the last item in the input
	while (request.inputIndex < inputPathLength) {

		// Check the available time
		long currentTime = TimeUtils.nanoTime();
		timeToRun -= currentTime - lastTime;
		if (timeToRun <= PathFinderQueue.TIME_TOLERANCE) return false;

		// Set the ray
		ray.start.set(path.getNodePosition(request.outputIndex - 1));
		ray.end.set(path.getNodePosition(request.inputIndex));

		// Do the ray cast
		boolean collided = raycastCollisionDetector.collides(ray);

		if (collided) {
			// The ray test failed, swap nodes and consider the next output node
			path.swapNodes(request.outputIndex, request.inputIndex - 1);
			request.outputIndex++;
		}

		// Consider the next input node
		request.inputIndex++;

		// Store the current time
		lastTime = currentTime;
	}

	// Reached the last input node, always add it to the smoothed path
	path.swapNodes(request.outputIndex, request.inputIndex - 1);
	path.truncatePath(request.outputIndex + 1);

	// Smooth completed
	return true;
}
 
Example 20
Source File: TimeScorer.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void pause() {
    pauseTime = TimeUtils.nanoTime();
    pausedTimeLeft = getTimeLeft();
}