Pygame : player sprite that disappears behind the background

So there you go, I wanted to experiment a little pygame but I find myself stuck. Context I created a small sprite (with Piskelapp) that represents the player and looks like: player.png then add my background in jpg format. However when launching the game, my sprite is cut by the background as follows: The ship is not placed in front of the background and more I go up it, more it disappears behind the background… Here is my code: anyone have a tip? I’m wondering if it’s not a file format problem? thank you for your time Answer In you

How do I change the volume in realtime for my music player (pygame)

I am trying to change the volume of my music in realtime for my music player. My code: And here are the action events: But I don’t know how to change the volume while the music is playing, it only changes the volume after I restart the song. I tried: But that didn’t work it just game me an error. Answer If you don’t use OOP(and I dont think you do based on what you provided), this should be the solution:

Running two files on a single project on PyCharm

I am currently developing a IoT sensor value simulator using the PyCharm IDE (along with pygame). Essentially, I am trying to produce/send data to Microsoft Azure IoT platform while there is a GUI available for users, in which they can see the temperatures of each sensor, change the sensor outputs, etc. Since I do not want to spam Azure with messages, I use sleep function between every messages sent to limit the rate of messages being sent. As a result, this slows down the whole application and it is a bit cumbersome. Is there a way to get around this

Pong in Pygame won’t count score

This is what I’ve got set-up, and I don’t want to be hand-fed the code as this is for a school project. I am still working on collision but I am not sure why the score being displayed isn’t being updated. I tried to set up the score update as a Dot method and then implement that method into the Game class then use the update method to try and update the displayed scores to show the new scores in the event that the ball hits either edge. Answer Look at your Game.update() method. Right now it looks like this:

Function name not defined error when i try to use recursion

I want to make a player that can shoot bullets. To do this i tried defining a shoot function that gets called when space bar is pressed. The function looks like this (p is the player object btw): I was hoping that the function would keep calling itself and the bullet would keep moving forward. However what actually happens is when i press space, it gives me an error How i called the function: Something i observed is that if i remove the recursion shoot() at the end of the shoot() function, it runs but the bullet stays in the

Why does it ignore my continue in the for-loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 months ago. Improve this question Hello I’m new here and would like to know, why my for-loop doesn’t react to the continue. It goes into the else branch. But just ignores the continue. Answer I suspect you have it backwards: continue is being executed when it shouldn’t be. You need to use elif for your sequence of conditions. Your else: block is only associated with the last

User needs to move mouse to fire bullet

When the user hits q to fire a bullet, there is no smooth motion. They need to move the mouse around the screen in order for the bullet to travel. I’ve tried looking around StackOverflow, youtube, reorganizing the code. I want the user to hit q and the bullet should fire with a parabola shape smoothly. Answer You’ve to do the update of the position in the main loop rather than the event loop. Note, the event loop is executed only when an event occurs. This means it is executed one time, when the button is pressed and a second

Antialiasing shapes in Pygame

I’m using Pygame to draw some things. The problem is that they have a lot of aliased edges: I want to make them softer, like this: My idea so far was to draw the shape in double size, and then use to shrink it to the size I want. Unfortunately if I’m drawing my shapes on a transparent surface, the smoothscale turns the edges that were touching transparent pixels black! How do I smoothscale a picture without turning alpha-transparent pixels into black, or How else do I antialias edges? Answer In order to draw antialiased filled shapes with pygame, use

how to play wav file in python?

I tried pygame for playing wav file like this: but It change the voice and I don’t know why! I read this link solutions and can’t solve my problem with playing wave file! for this solution I dont know what should I import? and for this solution /dev/dsp dosen’t exist in new version of linux : and when I tried pyglet It give me this error: Answer You can use PyAudio. An example here on my Linux it works: