Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Suppose I have a tile-based game and I want the step to be 1 tile but also want the movement to be smooth while the player is getting there. If I understand correctly, the only way to achieve this would be making a series of small movements where the increment is a percentage of a tile.

My question is: should the game logic thread send the animations to the rendering thread? What is the best way to go about it?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

To keep rendering perfectly separate from the game logic, animations - at least the ones that have no game logic impact - are solely done from the "rendering" side. A common pattern is to record the transition using three bits of data:

  • Start value
  • End value
  • Time (between 0 and 1)

The advantage of this approach is that it can be easily fed into an easing function so you can choose a style that suits.

To use this pattern, you detect whenever the player has moved from one tile to another. The start value will be the position of the previous tile, the end value will be that of the current tile, but to figure out time you need to record when the player began moving, and compare that against the current game time.

That's not the only method though; a simpler method would be to track the player's position in the "rendering" side, and constantly move this position towards the "game logic"'s position.

But finally, don't be so concerned about having the perfect design, especially when making games; if it's easier to hold some "rendering" data in the "game logic", just do it - you can clean it up later if it's hampering things.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.