Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pygame - moving graphic (Actor)

I'm just making a little game with Pygame. Objects should move across the screen. When I try to do this, a "track" is always dragged along (see picture). How can I move the apple without drawing the "course" of the movement?

from random import randint
import pygame

WIDTH   = 800
HEIGHT  = 800

apple = Actor("apple")
apple.pos = randint(0, 800), randint(800, 1600)

score = 0

def draw():
    apple.draw()
    screen.draw.text("Punkte: " + str(score), (700, 5), color = "white")

def update():
    if apple.y > 0:
        apple.y = apple.y - 4
    else: 
        apple.x = randint(0, 800)
        apple.y = randint(800, 1600)

enter image description here

like image 594
yellowcake Avatar asked Oct 15 '25 20:10

yellowcake


1 Answers

This is not pure pygame, it is Pygame Zero. You've to call screen.clear() to clear the display in every frame:

def draw():
    screen.clear()
    apple.draw()
    screen.draw.text("Punkte: " + str(score), (700, 5), color = "white")
like image 76
Rabbid76 Avatar answered Oct 17 '25 10:10

Rabbid76