Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class GuyRunningToTheRightAllTheTime
- {
- private Vector2 lastPosition;
- private Vector2 currentPosition;
- public GuyRunningToTheRightAllTheTime(Vector2 position)
- {
- // Set both last and current to this position
- lastPosition = position;
- currentPosition = position;
- }
- public void UpdateLogic()
- {
- // Store our current position as our last position
- lastPosition = currentPosition;
- // Update current position by a fixed-step
- currentPosition += new Vector3(0.2, 0);
- }
- // Delta is a number between 0 and 1. It represents how much time has passed since the last logical frame
- public void UpdateGraphics(float delta)
- {
- // Calculate the difference between the 2 last frames, starting at the last position
- Vector2 differenceBetweenLast2Frames = (currentPosition - lastPosition);
- // Calculate the point on this vector based on how long it's been since the last logical frame
- Vector2 pointOnDifference = differenceBetweenLast2Frames * delta;
- // Add that difference to the lastPosition
- Vector2 graphicalPosition = pointOnDifference + lastPosition;
- // Draw the guy
- DrawAGuyAt(graphicalPosition );
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement