Skip to main content
Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Pygame advanced blitting options Layer sprites according to their vertical position

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

So I want that every tree sprite gets blitted at a specific position relatively withto be displayed either in front of or behind the player's coordinatesplayer 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.

Pygame advanced blitting options

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

So I want that every tree sprite gets blitted at a specific position relatively with the player's coordinates.

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.

Layer sprites according to their vertical position

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.

deleted 1111 characters in body; edited title
Source Link
Salem
  • 226
  • 1
  • 17

Pygame advanced blitting and collision options

I need advanced collision detection and blitting options in my game as the latter is a 2D game that has trees' sprites along with the player's sprite.

For the blitting options:

So I want that every tree sprite gets blitted at a specific position relatively with the player's coordinates. Take a look at the images below:

CASE 1 :

case 1

Case 2:

case2

So I just want to get the result shown in the previous pictures so that These are the game works a little more realistic though it's a 2D one.

For the Collision Detection:

partial collision detectionpossible cases :

As you can see in this image, I want to detect collision only between the player and a part of the tree (that's in this case the bottom of the trunk). This is because it won't be realistic at all to detect collision with the entire tree and prevent the player from moving "underneath" it (as it looks in 2d games).cases

Conclusion

Back to the blitting options, 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 ?

Regarding the collision detection, I also got a good idea in my mind that is to make an independent sprite for the part of the tree that I need to check collision with and blit it in a way that it can't seem to be independent from the entire tree and then check collision between it and player(s). Yet, I guess there is a better implementation using subsurfaces, no ?

To conclude,The reason why I want to implementsolve this problem is adding some depth and reality into the 2 features I have explained ingame though it's a coherent way2D one.

Pygame advanced blitting and collision options

I need advanced collision detection and blitting options in my game as the latter is a 2D game that has trees' sprites along with the player's sprite.

For the blitting options:

I want that every tree sprite gets blitted at a specific position relatively with the player's coordinates. Take a look at the images below:

CASE 1 :

case 1

Case 2:

case2

So I just want to get the result shown in the previous pictures so that the game works a little more realistic though it's a 2D one.

For the Collision Detection:

partial collision detection

As you can see in this image, I want to detect collision only between the player and a part of the tree (that's in this case the bottom of the trunk). This is because it won't be realistic at all to detect collision with the entire tree and prevent the player from moving "underneath" it (as it looks in 2d games).

Conclusion

Back to the blitting options, I have an idea in mind which is 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 ?

Regarding the collision detection, I also got a good idea in my mind that is to make an independent sprite for the part of the tree that I need to check collision with and blit it in a way that it can't seem to be independent from the entire tree and then check collision between it and player(s). Yet, I guess there is a better implementation using subsurfaces, no ?

To conclude, I want to implement the 2 features I have explained in a coherent way.

Pygame advanced blitting options

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

So I want that every tree sprite gets blitted at a specific position relatively with the player's coordinates.

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.

Source Link
Salem
  • 226
  • 1
  • 17

Pygame advanced blitting and collision options

I need advanced collision detection and blitting options in my game as the latter is a 2D game that has trees' sprites along with the player's sprite.

For the blitting options:

I want that every tree sprite gets blitted at a specific position relatively with the player's coordinates. Take a look at the images below:

CASE 1 :

case 1

Case 2:

case2

So I just want to get the result shown in the previous pictures so that the game works a little more realistic though it's a 2D one.

For the Collision Detection:

partial collision detection

As you can see in this image, I want to detect collision only between the player and a part of the tree (that's in this case the bottom of the trunk). This is because it won't be realistic at all to detect collision with the entire tree and prevent the player from moving "underneath" it (as it looks in 2d games).

Conclusion

Back to the blitting options, I have an idea in mind which is 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 ?

Regarding the collision detection, I also got a good idea in my mind that is to make an independent sprite for the part of the tree that I need to check collision with and blit it in a way that it can't seem to be independent from the entire tree and then check collision between it and player(s). Yet, I guess there is a better implementation using subsurfaces, no ?

To conclude, I want to implement the 2 features I have explained in a coherent way.