2
\$\begingroup\$

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?

\$\endgroup\$
1
  • \$\begingroup\$ This almost begs the question to me of why there even needs to exist separate rendering and logic threads at all in a game that is tile-based. This is a huge amount of added complexity to keep track of. \$\endgroup\$
    – Steven Lu
    Sep 2, 2014 at 14:47

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .