Skip to main content
Added update 1 (second possible solution)
Source Link
Miklas
  • 413
  • 2
  • 10

About the place of the camera location code: If you are not using the camera in the step() function (which your probably don't), it might get updated multiple times per frame, but only get used once in the draw() function. So to prevent a waste of calculations, I'd place it in the latter.

Related to the jittery camera: there is no good reason for using a projection matrix for camera movement. The projection matrix is generally only generated once in the initialization, and a view matrix is used to determine the rotations and translations of the camera. You can use the Matrix.translateM() function to create a view matrix that does nothing more than translate the camera. Then, before you render, use the combined view * projection matrix. (You can combine them using the Matrix.multiplyMM() function)

For more information about the topic of view/projection matrices, have a look at the following resources:

Update 1: In your code, you are using two different variables (character.getY() for the check, character.getVerticalSpeed() for the update).

Although the code

center += character.getVerticalSpeed();

and

center = character.getY(); 

should virtually do the same, could you give that second one a try? (The actual values might differ due to things such as floating point roundoffs).

About the place of the camera location code: If you are not using the camera in the step() function (which your probably don't), it might get updated multiple times per frame, but only get used once in the draw() function. So to prevent a waste of calculations, I'd place it in the latter.

Related to the jittery camera: there is no good reason for using a projection matrix for camera movement. The projection matrix is generally only generated once in the initialization, and a view matrix is used to determine the rotations and translations of the camera. You can use the Matrix.translateM() function to create a view matrix that does nothing more than translate the camera. Then, before you render, use the combined view * projection matrix. (You can combine them using the Matrix.multiplyMM() function)

For more information about the topic of view/projection matrices, have a look at the following resources:

About the place of the camera location code: If you are not using the camera in the step() function (which your probably don't), it might get updated multiple times per frame, but only get used once in the draw() function. So to prevent a waste of calculations, I'd place it in the latter.

Related to the jittery camera: there is no good reason for using a projection matrix for camera movement. The projection matrix is generally only generated once in the initialization, and a view matrix is used to determine the rotations and translations of the camera. You can use the Matrix.translateM() function to create a view matrix that does nothing more than translate the camera. Then, before you render, use the combined view * projection matrix. (You can combine them using the Matrix.multiplyMM() function)

For more information about the topic of view/projection matrices, have a look at the following resources:

Update 1: In your code, you are using two different variables (character.getY() for the check, character.getVerticalSpeed() for the update).

Although the code

center += character.getVerticalSpeed();

and

center = character.getY(); 

should virtually do the same, could you give that second one a try? (The actual values might differ due to things such as floating point roundoffs).

Source Link
Miklas
  • 413
  • 2
  • 10

About the place of the camera location code: If you are not using the camera in the step() function (which your probably don't), it might get updated multiple times per frame, but only get used once in the draw() function. So to prevent a waste of calculations, I'd place it in the latter.

Related to the jittery camera: there is no good reason for using a projection matrix for camera movement. The projection matrix is generally only generated once in the initialization, and a view matrix is used to determine the rotations and translations of the camera. You can use the Matrix.translateM() function to create a view matrix that does nothing more than translate the camera. Then, before you render, use the combined view * projection matrix. (You can combine them using the Matrix.multiplyMM() function)

For more information about the topic of view/projection matrices, have a look at the following resources: