I am currently trying to develop my first game in pyton using the pygame module. I render my Map in two seperate layers, the back- and foreground. If i want to create another pygame.Surface
object, where I blit the foreground onto the background. Here are the raw stats of the pygame.Surface
objects.
The background:
The foreground:
And here is the code for blitting the Images on a new Surface called IMAGE:
self.IMAGE = pygame.Surface((self.width*self.tile_size,self.height*self.tile_size))
self.IMAGE.blit(self.Image_background,(0,0))
self.IMAGE.blit(self.Image_foreground,(0,0))
And also the code for displaying them onto self.WINDOW:
self.WINDOW.blit(self.MAP.IMAGE,(0,0))
Even if i do it like this:
self.WINDOW.blit(self.MAP.Image_background,(0,0))
self.WINDOW.blit(self.MAP.Image_foreground,(0,0))
I will always end up with a blank screen, displaying nothing but the background color. The returned image MAP.IMAGE
except has all the needed proporties:
I really appreciate your help! Thank you in advance!
EDIT: Here is my code to update the display:
def update_display(self):
pygame.display.update()
self.WINDOW.fill(BLACK)
if self.SCREEN == "MENU":
self.render_menu()
if self.SCREEN == "NEW MAP":
self.render_builder()
pygame.display.flip()
Here is my code for displaying objects (just the map):
def render_builder(self):
if self.LAYER == self.layers[0]:
self.display(self.MAP.Image_background,(self.MAP.pos_x,self.MAP.pos_y),scale=False)
elif self.LAYER == self.layers[1]:
self.display(self.MAP.Image_foreground,(self.MAP.pos_x,self.MAP.pos_y),scale=False)
elif self.LAYER == self.layers[2]:
print(self.LAYER)
self.display(self.MAP.Image_background,(self.MAP.pos_x,self.MAP.pos_y),scale=False)
self.display(self.MAP.Image_foreground,(self.MAP.pos_x,self.MAP.pos_y),scale=False)
self.display(self.right_bar,self.right_bar.topleft,(123,100,123))
Here is my code for displaying anything on the Surface:
def display(self,what,where=None,color=None,scale=True):
'''"WHAT" is either a Rect, Surface or String
If displaying a String, no "WHERE" is needed, otherwise use a Tuple (x,y)
Default "COLOR" is White, use a tuple to change that (Red,Green,Blue)'''
if type(what) == pygame.Rect:
if color:
pygame.draw.rect(self.WINDOW,color,what)
else:
pygame.draw.rect(self.WINDOW,WHITE,what)
elif type(what) == pygame.Surface:
if scale:
what = pygame.transform.scale(what,(self.true_tilesize,self.true_tilesize))
self.WINDOW.blit(what,where)
else:
self.WINDOW.blit(what,where)
elif type(what) == str:
if color:
text_surface = self.FONT.render(what,False,color)
else:
text_surface = self.FONT.render(what,False,BLACK)
text_rect = text_surface.get_rect()
text_rect.center = where
self.WINDOW.blit(text_surface,text_rect)