How can I move the ball instead of leaving a trail all over the screen in pygame?

You have to clear the display in every frame with pygame.Surface.fill: while True: # […] screen.fill(0) # <— main.draw_elements() main.move_ball() main.ball.x_pos += main.ball.speed pygame.display.flip() # […] Everything that is drawn is drawn on the target surface. The entire scene is redraw in each frame. Therefore the display needs to be cleared at the begin of … Read more

How do I scale a PyGame image (Surface) with respect to its center?

You missed to update the size of self.pixeltitlerect after the Surface has been scaled: self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize)) # size of surface has been changed get the new rectangle self.pixeltitlerect = self.pixeltitle.get_rect() self.pixeltitlerect.center = (250,120) self.screen.blit(self.pixeltitle,self.pixeltitlerect) Or even shorter (see pygame.Surface.get_rect()): self.pixeltitle = pg.transform.scale(self.pixeltitle,(xsize,ysize)) self.pixeltitlerect = self.pixeltitle.get_rect(center = (250,120)) self.screen.blit(self.pixeltitle,self.pixeltitlerect) Do not scale the original Surface. … Read more

rect collision with list of rects

Use pygame.Rect.collidelist to test whether a rectangle collides with one of a list of rectangles. collidelist: Test whether the rectangle collides with any in a sequence of rectangles. The index of the first collision found is returned. If no collisions are found an index of -1 is returned. if player_rect.collidelist(tile_rects) >= 0: # […]

SVG: text inside rect

This is not possible. If you want to display text inside a rect element you should put them both in a group with the text element coming after the rect element ( so it appears on top ). <svg xmlns=”http://www.w3.org/2000/svg”> <g> <rect x=”0″ y=”0″ width=”100″ height=”100″ fill=”red”></rect> <text x=”0″ y=”50″ font-family=”Verdana” font-size=”35″ fill=”blue”>Hello</text> </g> </svg>

How can I make the ball move instead of stretch in pygame?

You have to clear the display in every frame with pygame.Surface.fill: while True: # […] screen.fill(0) # <— main.draw_elements() main.move_ball() main.ball.x_pos += main.ball.speed pygame.display.flip() # […] Everything that is drawn is drawn on the target surface. The entire scene is redraw in each frame. Therefore the display needs to be cleared at the begin of … Read more