Pygame (Python Game Development) Tutorial - 49 - Button Functions

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

You can also use less variables in that function. Instead of using x, y, width, height you can store those parameters in a tuple, and index them like that:

example call of a function:
button("Play", loc=(50, 500, 100, 50), green, green2)

if statment:
if loc[0] + loc[2] > cur[0] > loc[0] and loc[1] + loc[3] > cur[1] > loc[1]:
pygame.draw.rect(gameDisplay, active_colour, loc)

Using less variables = cleaner code

CharlesMay
Автор

alternate version of the button function if statement:-

if abs(x-cur[0]) <= width and abs(y-cur[1]) <= height :

AnwarKhan-onsb
Автор

i did everything the same but when i did this function it wont draw the rectangle but it did write the text.. any advice?

ashash
Автор

pygame.draw.rect(gameDisplay, inactive_color (x, y, width, height))
TypeError: 'tuple' object is not callable
what is wrong?

jarhead_
Автор

I realize this is an old series, but why are you teaching people to use an OOP language without using classes?

justintenney