0

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:

Background

The foreground:

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:

complete

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)

lMortimerl
  • 21
  • 4
  • 2
    Did you even updated your screen ? Otherwise images just can't be blited onto your window. – ƒkS124 Jan 28 '21 at 22:24
  • What is `self.MAP.Image_background` ? Is it a loaded image? Another (blank) `Surface`? Are you `flush()`ing or `update()`ing your display? Maybe start with some simpler code and work-up from there. – Kingsley Jan 28 '21 at 22:44
  • Yes my screen gets updated inside the `update_display()` function i can copy it here if you want to, but it is just a lot of code. – lMortimerl Jan 28 '21 at 22:53
  • @Kingsley `self.MAP.Image_background` is a loaded `pygame.Surface` object displaying it on its own works just fine, but as soon as i want to display the `self.MAP.Image_foreground` surface in addition to the `self.MAP.Image_foreground` I get no image at all. – lMortimerl Jan 28 '21 at 22:56
  • So `self.MAP.Image_foreground` has transparent areas? Has it per pixel alpha? Do you set a color key ([`set_colorkey`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.set_colorkey))? Do you use [`convert_alpha()`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.convert_alpha)? – Rabbid76 Feb 01 '21 at 06:45
  • 1
    @Rabbid76 Thanks! `set_colorkey((0,0,0))` fixed the proplem! – lMortimerl Feb 01 '21 at 17:17

0 Answers0