Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

python - I drew a Ball from class and It's stuck in the same place (python3/pygame)

I have a Ball class and I drew a ball from that class. No matter what coordinates I put the ball is either stuck in the low middle part of the window or dissapears completely

#windowsize is (1200, 600)

class Ball():

def __init__(self,x,y,radius,color):
    self.x = x
    self.y = y
    self.radius = radius
    self.color  = color

def Draw(self,screen):
    pygame.draw.circle(window,self.color,[self.x,self.x],self.radius)

ball   = Ball(600,300,8,red)

while loop:
    ball.Draw(window)
    pygame.display.flip

screenshot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are 2 typos:

The parentheses are missing after pygame.display.flip

pygame.display.flip

pygame.display.flip()

The ball is drawn at [self.x,self.x] rather than [self.x,self.y]:

pygame.draw.circle(window,self.color,[self.x,self.x],self.radius)

pygame.draw.circle(window,self.color, [self.x, self.y], self.radius)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...