Jump to content

Pygame Tutorial - Graphics

- - - - -

  • Please log in to reply
No replies to this topic

#1
Cory Duchesne

Cory Duchesne

    Newbie

  • Members
  • PipPip
  • 10 posts
Hello, I'm having much difficulty with a chapter from an online book.

Here is the chapter:

Chapter 17

you can download the source code here.

The confusion starts shortly after the bolded line:

Fonts, and the pygame.font.SysFont() Function

Everything makes sense until line 23. He explains the code on line 22 very well, but then suddenly it seems like line 23 is skipped, there's no explanation on it.

I also don't understand line 24 or 25, there doesn't seem to be much of a direct explanation for those lines, which is uncharacteristic of the book.

Instead, there is a sub heading titled Attributes where he talks about the pygame.Rect data type. But I've looked over the lines of code carefully, and nowhere in the program is there any module named Rect. However, there is a method called get_rect() that gets appended to the surface object. He goes on to explain that the surface object is stored in the variable "text", and from what I can see, this surface object gets appended to the get_rect method, which I'm guessing turns it into a rect object, and this object is stored in the variable textRect. Establishing the textRect variable happens on line 23, and there is very little explanation on it. I assume line 23 is the creation of the a rect object, but I could be wrong.

My theory is that using the get_rect method somehow invokes the Rect module. But don't you need to call the module first before you can use any of the modules methods?

I read further along the chapter to get clearer on the get_rect method, but I found that it got more confusing. He said:

"Notice that both the Font object (stored in the text variable) and the Surface object (stored in windowSurface variable) both have a method called get_rect()."

See, this seems to completely contradict what he said earlier as well as the code itself. Early in the chapter he said he stored the surface object in the text variable, and I can see that for myself. The font object was stored in the basicFont variable, and I can see that as well. Why is he saying the font object is stored in the text variable? It's not. Same for the surface object, it is clearly not stored int he windowSurface variable.

Very confusing!

The book has been fantastic, and I've learned a lot, but chapter 17 is really giving me trouble.

Hopefully the problem is with me and not the book! I look forward to your reply, thanks.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users