Pygame (Python Game Development) Tutorial - 27 - Centering Text

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

I want to thank you one more time for making such a simple and direct tutorial with pygame...

It´s helping me a

Kerberos
Автор

Wait, what was the point of creating that second function if you can just do all of that work in the message to screen function as such? (seems simpler this way)

def message_to_screen(msg, color):
    text_surf = font.render(msg, True, color)
    text_rect = text_surf.get_rect()
    text_rect.center = (display_width/2), (display_height/2)
    gameDisplay.blit(text_surf, text_rect)

kristian
Автор

simpler alternative
def message_to_screen(msg, color):
screen_text = font.render(msg, True, color)
text_rect = / 2, screen_height / 2))
gameDisplay.blit(screen_text, text_rect)

gogo
Автор

so should we rebuild the game from scratch ourselves in order to master the contents and all the necessary parts that were explained throughout the snake series ... I mean that will make sense to me as I've not understood much functionality of the game (mostly mathematics) ... can someone tell if it's a good practice to rebuild something from the beggining like without any references and all by using our memories and unleashing our creativity?

yassir
Автор

If I understand properly, text_objects returns textSurface as -> textSurf and textSurface.get_rect() as -> textRect.
textSurface just renders the text and textSurface.get_rect() gets the rectangle area of the text.
So now you have the text itself and it's rectangle area. So at the end you "paste" the text onto the canvas and you center the middle of its rectangle.

adygombos
Автор

Nice tutorial 👍, I think we can also take out the width of the rendered text using get_width() and then subtract it's half from the (Screenwidth/2), that will also give the same thing right..
gameDisplay.blit(screen_text, [display_width/2-(screen_text.get_widtg()//2, display_height/2
cuz that works for me and I have seen it, anyways no prob with that..

vaibhavkrkm
Автор

How do you do this with other font ;-;

hcos
Автор

how to insert jpg or png sprites in pygame.. please help

SupachaiAbusali
Автор

I didn't understand all these Surf and Rect stuff... ;(

daniildimitrov
Автор

Can anyone point me in the direction where I can learn this texSurf, TextRect crap I just don't understand.

Автор

there's a smaller step to center the text
in "gameDisplay.blit(screen_text, [display_width/4, display_height/2])" i converted the 2 int 4
display_width/4

sarthakbawal
Автор

Dude i did not understand any of the stuff in this video, with all other videos you do a great job with explaining but in this one you really flopped, sorry.

tomislavvinkovic
Автор

So far, most confusing video. There are a lot of easier ways to do this

echeesez
welcome to shbcf.ru