SFML community forums

Help => Graphics => Topic started by: Jan666 on October 06, 2022, 12:07:10 am

Title: Change drawable objects hierarchy ?
Post by: Jan666 on October 06, 2022, 12:07:10 am
So i wanna make a beat em up game, you see the player from the side but you can also walk up an down. So i need to fix following: When the player is on the y axis higher than another object, the player have to be behind it and when the player's y axis is lower than the object , he is in front of it. Exist there something like to change the drawable objects hierarchy while the game i running and compare the y- axis of the booth?
Title: Re: Change drawable objects hierarchy ?
Post by: Jan666 on October 06, 2022, 08:08:10 am
For better understanding i post the following code, what i mean, i

if(playerPos.y > enemyPos.y){
                window.draw(player);
                window.draw(enemy);}
                else{
                        window.draw(enemy);
                        window.draw(player);
                }

 
Title: Re: Change drawable objects hierarchy ?
Post by: eXpl0it3r on October 06, 2022, 08:46:31 am
No, SFML always uses the painter's algorithm (https://en.wikipedia.org/wiki/Painter%27s_algorithm) meaning, whatever you draw first will be the thing in the back and what you draw afterwards, will be drawn over the previous thing.

So if you want to have a specific draw order, you'll have to implement that logic yourself.