Skip to content

Tag: pygame

How can I play song repeatedly using pygame.mixer.music.play()?

I have tried to repeat a song(mp3) using pygame module. The code is as follows from the site https://www.studytonight.com/tkinter/music-player-application-using-tkinter When calling this function, it comes out only one time, of course it’s natural. To repeat this sound file I added loop like this, but i…

Pygame How to check for second press of a key

Hi guys i’m making a game in python using pygame. I have a piece of code that shoots lasers from a ship in a space themed game. Here is the code: Well this piece of code shoots two lasers from the ship, like this. But i don’t want that. I want to make if player presses space once shoot the

I want this cube in pygame to move when I update it

My cube in which I am updating to move 5 pixels every frame, will not move. I have checked my code and I cannot find the issue, send pizza. I wish to make the cube move right 5 pixels every frame. separate file separat file Answer You have to create the instance of the Game class before the application loop:

Move Character with Vector

I am teaching myself pygame and am looking at making my character able to rotate and then move in the direction they are facing. I can do the rotation but cannot get the character to move in the direction the image is then facing. The code is on Trinket HERE Answer Rotate the player around its center (see How…

PyGame: issue with MOUSEBUTTONDOWN events

I’m trying to build a game of Chess in PyGame. My code is something like this: What I’m trying to do is this: The first MOUSEDOWNEVENT will select a piece that the user clicks on. If the user didn’t click on the piece, it will simply return None. The second MOUSEDOWNEVENT will actually move …

How can I rotate this object back and forth forever?

I have a bone arrow image that rotates. If it reaches a certain timer I want it to stop rotating on one side and start rotating the other. If the other side reaches its timer it should goes back and forth, back and forth, like this short gameplay video. I don’t know why it stops when its timer2 turn at