Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit eb3abd68a107d089c7af47b433e99cda5b5c9ffa
parent 19ecaff30760990bb35c8e698cff05443c778aeb
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat, 17 Oct 2020 14:10:11 -0500

StillScene text now rendering correctly

Diffstat:
Mdata/json/scenes/testscene.json | 2+-
Msrc/scene.py | 31++++++++++++++-----------------
2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -1,7 +1,7 @@ { "name" : "TestScene", "fonts" : { - "A" : ["ArchivoNarrow-Regular.otf", 16] + "A" : ["ArchivoNarrow-Regular.otf", 22] }, "bg_sheet" : "test_scene_bg_1", "bg_sprite" : [0, 0], diff --git a/src/scene.py b/src/scene.py @@ -69,7 +69,7 @@ class StillScene(object): self.script = [] self.fonts = {} self.characters = {} - self.text_speed = 10 + self.text_speed = 1 self.text_write_timer = 0 self.current_text_char_index = 0 self.continue_ready = False @@ -83,17 +83,17 @@ class StillScene(object): self.text_box_pos = (0, 508) self.continue_prompt = None self.continue_prompt_pos = (964, 748) - self.text_surface = pygame.Surface((928, 196)).convert() - self.text_surface.set_colorkey((255, 0, 255)) - self.text_surface_pos = (48, 540) + self.text_area_topleft = (48, 540) self.background = None # Swap-in values self.displayed_characters = pygame.sprite.LayeredDirty() self.current_text_string = "" self.displayed_strings = [""] # list of text lines + self.rendered_text_surfaces = [None] self.line_number = 0 self.current_font = None # An index of the 'fonts' value + self.current_font_height = 0 self.current_text_voice = None self.script_index = -1 @@ -135,6 +135,7 @@ class StillScene(object): """ # First, clear up and prepare self.displayed_strings = [""] + self.rendered_text_surfaces = [None] self.line_number = 0 # NOTE: The displayed_characters group is not emptied here. # That must be done manually in a script event. @@ -142,6 +143,7 @@ class StillScene(object): # Next, load up the next segment self.script_index += 1 self.current_font = self.fonts[self.script[self.script_index]["line_font"]] + self.current_font_height = self.current_font.get_height() self.current_text_string = self.script[self.script_index]["line"] def write_text(self): @@ -166,17 +168,11 @@ class StillScene(object): # Check if we need to add a new line if len(self.displayed_strings[self.line_number]) >= self.max_line: self.displayed_strings.append("") + self.rendered_text_surfaces.append(None) self.line_number += 1 # Render to a surface - for l in self.displayed_strings: - d = self.current_font.render(l, True, (0, 0, 255)).convert() - #self.text_surface.blit(d, self.text_surface_pos) - self.manager.game.screen.blit(d, self.text_surface_pos) - # TODO: Text getting immediately erased - # Make d here permenant to text_surface somehow - # Should prob be stored in a var and blitted outside - # of this func + self.rendered_text_surfaces[self.line_number] = self.current_font.render(self.displayed_strings[self.line_number], False, (0, 0, 0)).convert() # Check if we have written the last character if self.current_text_char_index >= len(self.current_text_string) - 1: @@ -203,8 +199,9 @@ class StillScene(object): if self.continue_ready: self.continue_prompt.update(surface) - if self.text_surface != None: - #self.text_surface.fill((255, 255, 255)) - self.write_text() - #surface.blit(self.text_surface, self.text_surface_pos) - + self.write_text() + l = 0 + for t in self.rendered_text_surfaces: + if t != None: + surface.blit(t, (self.text_area_topleft[0], self.text_area_topleft[1] + (self.current_font_height * l) + 2)) + l += 1