The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
ZhangXunqi (8) [Avatar] Offline
Hi! Mr.Sande,or other friends,I need your help.Does my questions are too difficult to work out?Why not say something?0 reply makes me really sad!
Ok,still chapter 17:I let example 17.2 have a little change,because I can't understand it clearly.I try to know every variable's change rule.So you can see I nearly print every variable every loop when the ball runs(To think easily,I only play one ball)I think it can help me know hiw does the code run.Here is the code:
Maybe you can't see the indent.Here please regard '~' as a blank.
from random import *
class MyBallClass(pygame.sprite.Sprite):
~~~~def __init__(self,image_file,location,speed):
~~~~~~~~ pygame.sprite.Sprite.__init__(self)
~~~~def move(self):
~~~~~~~~print "##",self.rect
~~~~~~~~self.rect=self.rect.move(self.speed) #NOTICE HERE!!
~~~~~~~~print "##",self.rect
~~~~~~~~if self.rect.left<0 or self.rect.right>width:
~~~~~~~~if<0 or self.rect.bottom>height:

while True:
~~~~for event in pygame.event.get():
~~~~~~~~if event.type==pygame.QUIT:
~~~~print "========================="
~~~~print ball.rect
~~~~print ball.rect.left
~~~~print ball.rect.right
~~~~print ball.rect.bottom
~~~~print speed[0]
~~~~print speed[1]

Did you see "NOTICE HERE" ---self.rect=self.rect.move(self.speed)?I find self.rect changed from there.How does the code do it?I think this line must be the soul of this code?
Dear Mr. Sanda.Could you please give your opinions?