Jan-05-2023, 09:32 PM
(This post was last modified: Jan-06-2023, 12:48 AM by Yoriz.
Edit Reason: removed unnecessary quote of previous post
)
If I write (x - width), there's a part of the text outside from the left side of the window, I changed it to (x + width and then it's in the center, but not completely centered, example from the game and the part of the code:
1) x - width
https://gofile.io/d/AmugVb
https://gofile.io/d/zgag83
1) x - width
https://gofile.io/d/AmugVb
def blit_text(surface, msg, pos, font, color = pygame.Color('dodgerblue')): x, y = pos m = msg.split('\n') for line in m: text = pygame.font.Font(None, 48).render(line, True, msg_color) width, height = text.get_size() surface.blit(text, (x - width/2, y - height/2)) y += height + 2.2) x + width
https://gofile.io/d/zgag83
def blit_text(surface, msg, pos, font, color = pygame.Color('dodgerblue')): x, y = pos m = msg.split('\n') for line in m: text = pygame.font.Font(None, 48).render(line, True, msg_color) width, height = text.get_size() surface.blit(text, (x + width/2, y - height/2)) y += height + 2.EDIT: sorry, maybe my bad beacuse of this:
if msg: text = pygame.font.Font(None, 48).render(msg, True, msg_color) pos = center.x - text.get_width() / 2, center.y * 2 - text.get_height() <-- "because of this line" blit_text(surface, msg, pos, None, color = pygame.Color('dodgerblue'))But can I somehow make that part responsive for any text length?