com.badlogic.gdx.utils.TimeUtils Java Examples

The following examples show how to use com.badlogic.gdx.utils.TimeUtils. 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: VisSpeller.java    From buffer_bci with 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 #2
Source File: OrthographicCameraExercise.java    From ud405 with 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 #3
Source File: RectangleCircleCollisionScreen.java    From ud406 with 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 #4
Source File: BMControllerInputProcessor.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
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 #5
Source File: Input.java    From uracer-kotd with 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 #6
Source File: Demos.java    From collider with 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 #7
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 #8
Source File: HTMLGDXFacebook.java    From gdx-facebook with 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 #9
Source File: Game.java    From shattered-pixel-dungeon with 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 #10
Source File: GameEngine.java    From collider with Apache License 2.0 5 votes vote down vote up
public void stepToTime(double time) {
	if(time < getTime()) return;
	long startNanoTime = TimeUtils.nanoTime();
	if(time > getTime() && mouseListener != null) {
		double x = SCREEN_WIDTH*Gdx.input.getX()/(double)Gdx.graphics.getWidth();
		double y = SCREEN_HEIGHT*(1.0 - Gdx.input.getY()/(double)Gdx.graphics.getHeight());
		x = Math.max(0, Math.min(SCREEN_WIDTH, x));
		y = Math.max(0, Math.min(SCREEN_HEIGHT, y));
		mouseListener.updateMousePos(time, x, y);
	}
	processes.stepToTime(time);
	otherWork += (TimeUtils.nanoTime() - startNanoTime);
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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;
}
 
Example #16
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 #17
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 #18
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;
}
 
Example #19
Source File: HTMLGDXFacebook.java    From gdx-facebook with 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 #20
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 #21
Source File: PacketTuple.java    From riiablo with 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;
}
 
Example #22
Source File: Server.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void Ping(ChannelHandlerContext ctx, SocketAddress from, D2GSPacket packet) {
  Ping ping = (Ping) packet.data.data(new Ping());
  FlatBufferBuilder builder = new FlatBufferBuilder(0);
  int dataOffset = Ping.createPing(builder, ping.tickCount(), ping.sendTime(), TimeUtils.millis() - packet.time, false);
  int root = D2GS.createD2GS(builder, D2GSData.Ping, dataOffset);
  D2GS.finishSizePrefixedD2GSBuffer(builder, root);
  D2GSPacket response = D2GSPacket.obtain(1 << packet.id, D2GSData.Ping, builder.dataBuffer());
  outPackets.offer(response);
}
 
Example #23
Source File: D2GS.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void Ping(Packet packet) {
  Ping ping = (Ping) packet.data.data(new Ping());
  FlatBufferBuilder builder = new FlatBufferBuilder(0);
  int dataOffset = Ping.createPing(builder, ping.tickCount(), ping.sendTime(), TimeUtils.millis() - packet.time, false);
  int root = com.riiablo.net.packet.d2gs.D2GS.createD2GS(builder, D2GSData.Ping, dataOffset);
  com.riiablo.net.packet.d2gs.D2GS.finishSizePrefixedD2GSBuffer(builder, root);
  Packet response = Packet.obtain(1 << packet.id, builder.dataBuffer());
  outPackets.offer(response);
}
 
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: OrthographicCameraExercise.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void create() {
    renderer = new ShapeRenderer();
    timeCreated = TimeUtils.millis();

    // TODO: Initialize the camera
    camera = new OrthographicCamera();

    // TODO: Set the camera's position to the center of the circle's movement (X_CENTER, Y_CENTER)
    camera.position.set(X_CENTER, Y_CENTER, 0);
}
 
Example #30
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;
}