Szöveg szélesség számítás fix
This commit is contained in:
15
src/text.py
15
src/text.py
@@ -83,9 +83,19 @@ class TextRenderer:
|
||||
for s in self.sprites:
|
||||
s[1] = s[1].move(x, y)
|
||||
|
||||
# !!! ChatGPT !!!
|
||||
def render(self, discoloration=(255,255,255)):
|
||||
offset = -(sum(s[2] for s in self.sprites) // 2) if self.center else 0
|
||||
for s in self.sprites:
|
||||
offsets = []
|
||||
sprite_idx = 0
|
||||
for line in self.text.split('\n'):
|
||||
line_len = len(line)
|
||||
line_sprites = self.sprites[sprite_idx : sprite_idx + line_len]
|
||||
line_width = sum(s[2] for s in line_sprites)
|
||||
line_offset = -(line_width // 2) if self.center else 0
|
||||
offsets.extend([line_offset] * len(line_sprites))
|
||||
sprite_idx += line_len
|
||||
|
||||
for s, offset in zip(self.sprites, offsets):
|
||||
arcade.draw_texture_rect(
|
||||
s[0],
|
||||
s[1].move(offset, 0),
|
||||
@@ -93,6 +103,7 @@ class TextRenderer:
|
||||
color=arcade.types.Color(*discoloration)
|
||||
)
|
||||
|
||||
# !!! ChatGPT vége !!!
|
||||
# a \n display függvénye
|
||||
def newline(self):
|
||||
self.y -= 13
|
||||
|
||||
Reference in New Issue
Block a user