0
\$\begingroup\$

I need advanced blitting options in my game. It's a 2D game that has trees' sprites along with the player's sprite.

I want that every tree sprite to be displayed either in front of or behind the player sprite, depending on whether the player is standing higher or lower on the screen than the tree's base.

These are the possible cases :

cases

I have an idea in mind, which is to check for the player's coordinates and depending on them, blit the tree's sprite underneath it or above it (respecting the layers system). However, I think that this won't work or will make the tree's sprite flicker in case there is more than one player (or another object that can pass beside the tree). So what is a good solution for that ?

The reason why I want to solve this problem is adding some depth and reality into the game though it's a 2D one.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ The idea you have in mind sounds like it matches the way common game engines solve this problem. When you test your idea, does it exhibit the problems you say you think it might? If so, please share with us a Minimal Complete Verifiable Example of that problem, and we can help you fix it. If not, then it might be a good enough solution for your needs. \$\endgroup\$ Commented Sep 9, 2021 at 18:33
  • \$\begingroup\$ @DMGregory, I have just tested that implementaion with only one sprite and it failed ! Once the sprite's coordinates change relatively to the tree's sprite ones, I could notice that the tree's sprite flickers. \$\endgroup\$ Commented Sep 9, 2021 at 18:39
  • 1
    \$\begingroup\$ Please proceed to edit your question to include the minimal complete verifiable example, then. We may be able to spot what causes the flicker and help you fix that problem. \$\endgroup\$ Commented Sep 9, 2021 at 18:42

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.