Pygame (A bit racey) Objects are there, but not visible
<p>I have a couple of objects defined/entered into a variable</p>

<pre><code>car1 = pygame.image.load('C:\Users\itzrb_000\Downloads\download (3).png')
car2 = pygame.image.load('C:\Users\itzrb_000\Downloads\download (2).png')
car3 = pygame.image.load('C:\Users\itzrb_000\Downloads\images.png')
rock = pygame.image.load('C:\Users\itzrb_000\Downloads\Rock.png')
</code></pre>

<p>Then created a function called <code>cars</code> which takes the x and y start position as arguments</p>

<pre><code>def cars(thingx, thingy):
    objects = [car1, car2, car3, rock]
    num_of_objects = random.randint(1,4)
    for x in range(num_of_objects):
        y = random.choice(objects)
        gameDisplay.blit(y,(random.randrange(130, 625),-300))
</code></pre>

<p>inside the <code>game_loop</code> function</p>

<pre><code>thing_startx = random.randrange(130,625)
thing_starty = -600
thing_speed = 10
</code></pre>

<p>Then I call all the objects</p>

<pre><code>background()
things(thing_startx, thing_starty, thing_width, thing_height, black)
car(x,y)
cars(thing_startx, thing_starty)
thing_starty += thing_speed
score(dodged)
</code></pre>

<p><code>car</code> is the car that the player plays with, <code>things</code> is a function that draws a black square that later on is the thing that I shouldn't crash into</p>

<pre><code>def things(thingx, thingy, thingw, thingh, color):
    pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])
</code></pre>

<p>I'm trying to display the car images instead of just a black block, I commented out the <code>things</code> function and its call in <code>game_loop</code>. When I tested there's nothing visible, however I noticed that my car at some point crashes, so the conclusion is that the car image is there, but it's not visible.</p>

<p>Any idea on how to solve this ?</p>

<p>You're blitting the objects off screen. <code>gameDisplay.blit(y,(random.randrange(130, 625),-300))</code> will blit the image at x between 130 to 625 and y at -300 (which means 300 to the left of the screen).</p>

<p>But is the function doing what you want it to do? Every loop you're blitting a random number of random objects at random positions. I strongly suggest finding a better tutorial which teaches basics as code structure, good naming, how to use docstrings and object-oriented programming, like <a href="https://www.youtube.com/watch?v=bMt47wvK6u0&amp;list=PL4Yp6gRH-R1Birdm-Gs-SdBFWLUC1q3Fa&amp;index=4" rel="nofollow">this</a>.</p>

python pygame