简体   繁体   中英

I made a very simple Pygame Zero game, but my Actor image and the screen.clear() is not working. Can you help me fix this?

This is the full code for the very bad game example.

import pgzrun
from random import randint
from pgzero.builtins import Actor, animate, keyboard

apple = Actor('apple')

def draw():
    screen.clear()
    apple.draw()

def place_apple():
    apple.x = randint(10, 800)
    apple.y = randint(10, 600)

def on_mouse_down(pos):
    if apple.collidepont(pos):
        print("Good shot!")
        place_apple()
    else:
        print("You missed!")
        quit()

place_apple()
pgzrun.go()

the screen.clear() isn't working and apple = actor("apple") also isn't working. I have no idea why. Please help me!

try this:

from pgzero.actor import Actor
from pgzero.keyboard import keyboard

not sure if it helps.

Are you using mu editor or pycharm??

Do you have an apple image in the correct path?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM