Jump to content

Stars not showing in pygame zero

ff_Floris
Go to solution Solved by adm0n,

You have never called star1.draw(), so he will never actually be drawn.

 

I'd also recommend not creating the actor inside the draw routine. Rather create your actor globally and then only call star1.draw() in the draw routine.
(I'd also recommend not moving it once per draw :D)

Im making a simple game where you can shoot stars in pygame zero, but after a bit of time coding i ran the code, but i didnt see the stars. Is there any way to fix this? (please note that some of these things are temporarily and i will remove them later on in the project)

import pgzrun
import random
import pygame
WIDTH=800
HEIGHT=600
amount_of_stars=10
clicked=False
def draw():
    screen.blit("bg1",(0,0))
    star1=Actor("star")
    star1.pos=random.randint(0,750),random.randint(0,550)

def update():
    global clicked
    mouse_x, mouse_y = pygame.mouse.get_pos()
    if clicked==True and star1.collidepoint(mouse_x, mouse_y):
        star1.pos=random.randint(0,750),random.randint(0,550)
        clicked=False
    #star.pos=random.randint(0,750),random.randint(0,550)
    
pgzrun.go()

 

Link to comment
Share on other sites

Link to post
Share on other sites

You have never called star1.draw(), so he will never actually be drawn.

 

I'd also recommend not creating the actor inside the draw routine. Rather create your actor globally and then only call star1.draw() in the draw routine.
(I'd also recommend not moving it once per draw :D)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×