Questions tagged [pygame]

1

votes
2

answer
45

Views

How to import an tmx map in pygame?

I have made a *tmx map in the Tiled Editor program. Then I tried to import it into my game. When I change the variable layers to 0 it works, but there is only 1 tile on the screen. I want to print the entire map on my screen. But I get the following error. Traceback (most recent call last): File "C:...
Erik77
1

votes
2

answer
982

Views

Pygame application runs slower on Mac than on PC

A friend and I are making a game in Python (2.7) with the Pygame module. I have mostly done the art for the game so far and he has mostly done the coding but eventually I plan to help code with him once most of the art is done. I am on a Mac (latest version of OS X) and my friend is using a PC. He...
Alex McMullen
2

votes
0

answer
22

Views

pygame window and python console application

I have a working single player text adventure in Python. It handles one word commands with lists. So a player can get things, drop things, wear clothes, and it has a combat system. I want to expand it. I have used pygame to build a map, following after a really great demo on YouTube, and now I am st...
Jonathan Engwall
1

votes
3

answer
3.4k

Views

How do I flip an image horizontally in pygame?

This is in pygame. How do I flip an image (lets say an image of a pig looking to the right) to look to the left when I press the left arrow key, and stay like that even if I don't press any keys or if I press the up and down arrow keys. Then how do I switch it back again to look to the right when I...
Katrina
1

votes
1

answer
413

Views

Pygame keeps crashing on mac

I started learning pygame, wrote a simple program to display some text on the screen. import pygame, time pygame.init() window = pygame.display.set_mode((600,300)) myfont = pygame.font.SysFont("Arial", 60) label = myfont.render("Hello Pygame!", 1, (255, 255, 0)) window.blit(label, (100, 100)) pygam...
nitte93user3232918
2

votes
1

answer
18

Views

(Python) Closing pygame.display in a Thread

I am trying to create a Thread that will continuously run in the background of my program and check whether or not the user has pressed the X button in the top right of the window, and then quit the program if they do press it. This way, no matter what is happening, the user may close the program at...
Alex
1

votes
2

answer
3k

Views

How to assign sounds to channels in Pygame?

I'm trying to play multiple sounds simultaneously in Pygame. I have a background music and I want a rain sound to play continuously and play ocasional thunder sounds. I have tried the following but my rain sound stops when thunder sound is playing. I have tried using channels but I don't know how to...
Sorade
1

votes
1

answer
152

Views

How to wrap text in pygame using pygame.font.Font()?

I am making a would you rather game, and I would like to not have character restrictions for the W.Y.R. questions. I have seen many examples here on Stack Overflow and other websites, but they use other modules and methods I don't understand how to use or want to use. So I would rather use button_t...
K. Turkey
1

votes
1

answer
30

Views

name “ClassName” is not defined even though im sure i imported correctly (Python)

I'm stuck at an error where U get a name error even though I'm sure I imported correctly. So I'm trying to create a class instance from one file referring to the other. The imports in the main file looks like this from movement import * from maps import * import pygame import sys pygame.init() # P...
August Krümmel
1

votes
2

answer
38

Views

How to get rect of a pygame Surface without transparent parts?

I am implementing collision detection and want to check if a rectangular object is touching the player. My wall uses .set_colorkey(background) where background is the specified background colour. The problem is that when I get my wall's rectangle with .get_rect(), it gets the full image's size which...
GeeTransit
1

votes
3

answer
47

Views

If x,y inside coordinate box

i have been trying to find an efficient solution to this: def hit(pos,box): if pos[0] > box[0]: if pos[0] < box[0]+box[2]: if pos[1] > box[1]: if pos[1] < box[1]+box[3]: return True return False pos = (50,132); box = (20,50,60,150) hit(pos,box) I am using pygame and want to calculate if the x,y coor...
Walter
1

votes
4

answer
89

Views

'int' object not callable?

I keep getting the error "int object not callable", but even after looking around the internet and stack overflow, i can't deduce the fix. I thought maybe it could've been caused by the pygame.quit function, but i'm not sure whats wrong with mine exactly. # Imports-----------------------------------...
Tyrone Pope
0

votes
0

answer
12

Views

Is there a way to not update pygame frames is nothing has happened?

I am designing a game in pygame at the moment and i was thinking how low my framerate was (an average of 7 fps). I investigated further and did convert_alpha() for all my images and I wondered if there was a simple way to make it so that if nothing in the window had changed the frames would not upda...
Guydangerous99
1

votes
3

answer
552

Views

How to write a function to map points on a canvas to points on the real plane

I'm writing a simple Mandelbrot visualiser in Python onto a pygame Screen. For each pixel on the 600 by 600 Screen, I am plotting whether or not this pixel, (x, y) as a complex number, is in the Mandelbrot set or not. The problem being that I start at (0, 0) and iterate through to (600, 600), most o...
persepolis
0

votes
0

answer
13

Views

How can I remove the black of some of the tile textures

So my program is a treasure hunt game that uses a collection of tiles for the game map and on these tiles I use PNG photos for the texture, however when using PNG photos that don't fully occupy a tile, black covers the rest of the tile. I am just wondering how can you remove the black and place one...
J.Peggy
1

votes
3

answer
1.2k

Views

Need Float Accuracy for moving objects on the screen Pygame

So I'm trying to get balls to spawn on random places on the frame and have them pass through the center of the screen. The only problem is, I'm having trouble updating the position with a float velocity. Therefore things aren't passing through the center they are a little bit off and its not how I w...
user3260745
1

votes
3

answer
8.3k

Views

How to uninstall pygame on mac OSX 10.9.4

In fact, I meet the problem that my pygame can not load png image and the method pygame.image.get_extended() returns 0, which means false Traceback (most recent call last): File "testpygame.py", line 5, in myimage = pygame.image.load("diamond.png") pygame.error: File is not a Windows BMP file I sea...
FionaMango
1

votes
2

answer
288

Views

How to properly clear all images that were “blitted” onscreen using pygame?

I was wondering how does pygame.blit manages the images blitted on screen. When I blit an multiple images on the screen, I see that each image is stacked on top the previous one. How do I clear all these images? Wouldn't(somehow) there be a big problem when there are LOTS of images stacking on top o...
iCodeLikeImDrunk
1

votes
1

answer
80

Views

Colliding Rects

I have been working on this game, but I have a question when it comes to collision detection. Can I check for collision and have it return True: example: def collide(self, EnemyTank): tank_collision = pygame.sprite.collide_rect(self.rect, EnemyTank.rect) if tank_collision == True: return True And t...
1

votes
1

answer
1.1k

Views

Receiving multiple messages via socketserver but one is sent

A have a application with two threads. Its a network controlled game, 1. thread (Server) Accept socket connections and receive messages When message is sent, create an event and add it to the queue Code: class SingleTCPHandler(SocketServer.StreamRequestHandler): def handle(self): try: while True: sl...
1

votes
2

answer
1.8k

Views

Pure python library for MIDI to Score (Notes) and/or Audio Translation

i want something that abstracts away midi events, to extract/synthesize notes' pitch/duration/dynamic/onset (e.g. loud D# quarter note on the 4th beat). fluidsynth and timidity work, but i'd prefer a pure python library. i can't find anything but bindings here. midiutil makes midis and pygame plays...
sam boosalis
1

votes
2

answer
5k

Views

How to flip an img in Pygame, having trouble in my code?

I'm having trouble flipping a sprite in pygame (I can get it to go right but I want the img to flip on the left key), I researched how to flip an image and found the pygame.transform.flip, but as a beginner to pygame, I'm not sure how to use it, and the tutorials aren't making sense to me. Can anyon...
MRG123
1

votes
2

answer
3.7k

Views

Drawing an Arrow in Pygame [duplicate]

This question already has an answer here: Rotation based on end points 4 answers Actually I am making a program to implement Minimum Average Latency ( Pipelining ) by using a reservation table... I have completed the back-end successfully and now trying to design the Transistion Diagram on Pygame.....
adil
1

votes
1

answer
184

Views

Pygame sprite not displaying for unknown reasons

Okay, so I have now tried to fix my Pygame code for 5 days so I can get the monster sprite drawn just like the platform sprites are already working. I can't find an error with my code and so do my friends neither. #!/usr/bin/env python # -*- coding: utf-8 -*- import pygame, random, sys, os from pyg...
jsk
1

votes
1

answer
1.3k

Views

How can I have my program wait for input, without being in a loop

I'm writing a Pygame program that takes user input to write music. It waits for a specific event (ie keyboard or mouse input) and immediately analyzes the input without the user pressing enter with each entry. while (running == 1): for event in pygame.event.get(): # If event is a keypress if(event.t...
Jonathan
1

votes
1

answer
4.3k

Views

Pygame sound on key press

Currently just trying out pygame and I've created a window with a white background and just an image. I want to be able to move the image using the arrow keys (working fine) as well as when an arrow key is being pressed, I want an engine sound mp3 to play. This is the code I've got at the moment: im...
1

votes
1

answer
1k

Views

pygame.key.set_repeat for Joystick

I'm building a menu using pygame and I want to make it navigable using a specific gamepad. Ideally I want to be able to press and hold *down" on the D-pad repeatedly, or get something like on a keyboard where the first button press has a delay before repeatedly entering the same character (seemingl...
Ryan Haining
1

votes
1

answer
391

Views

Pygame Sprite doesn't reset

I am making a platformer type game but I have run into two problems. My Sprite is confined to a small box in the centered in the window. How do I make it so he can cover the entire window? When I move the old sprite is not removed. It make it appear that there is a tail following the sprite. Help fo...
ddaniels
1

votes
1

answer
5.7k

Views

How to make a sprite follow your mouse cursor using pygame?

I am making a small game for a class project and am wondering how to make something follow my mouse cursor using pygame. I'm new to pygame so try to be understanding if it's obvious and I'm just stupid.
Ark Angel
1

votes
1

answer
374

Views

Pygame sprite assistance

I've basically just started developing with PyGame and I am having trouble with the whole Sprite concept. I have been looking every where for guides on how to use it, I just can't seem to find any. I would like to know the basic concept of how it all works. This is the code I have been working on: #...
ReallyGoodPie
1

votes
3

answer
1.1k

Views

Python pygame Detect if mouse is over non transparent part of surface

I am trying to make a UI for my game and there are some curves to the UI. Now I can detect collision between two surfaces. I can detect by pixel between two sprites, but it seems mouse detection by pixel is alluding me. Basically I want to detect when the mouse is over the UI and then ignore everyth...
Phreak Nation
1

votes
1

answer
214

Views

Testing for pygame sprite collision

I have been going through some pygame tutorials, and I have developed my own code based off of these tutorials. It is as follows: #!/usr/bin/python import pygame, sys from pygame.locals import * size = width, height = 320, 320 clock = pygame.time.Clock() xDirection = 0 yDirection = 0 xPosition = 32...
ReallyGoodPie
1

votes
1

answer
2.1k

Views

Simple 2D gravity with pygame; Value Guidelines?

I am trying to simulate gravity in a simple 2D window using pygame. It's very simple stuff (a dot rising and falling again) and I understand the mechanics, i.e. speed as a vector and the y portion being consistently diminished by a value g representing gravity during each run through the mainloop an...
Nebelhom
1

votes
2

answer
422

Views

Getting World Coordinates with mouse in pygame

I am having trouble updating the mouse position and checking for entity collisions (between the mouse and entity) due to my level scrolling. I have used the camera function from this question: How to add scrolling to platformer in pygame I have tried to use the camera function on the mouse like this...
ReallyGoodPie
1

votes
2

answer
1.6k

Views

Pygame Colliderect Not Functioning

Problem with Pygame! Colliderect function doesn't detect when two rects collide! The rects just fall through each other, though no error message is given. Why is this and how can it be fixed? Been struggling on this same problem for days on end! Supposed problem spot is labeled with a comment. Thank...
user2597443
1

votes
2

answer
3.1k

Views

Pygame: Font module not available

Running Python 2.7.2, and Pygame 1.9.2pre on OS X. Another noobious issue: Initialising the pygame.font module produces an error that I dare not... well, attempt to solve myself. I'm guessing this is a rather generic pygame-related issue... but I haven't been able to find any solutions. import pygam...
Jollywatt
1

votes
2

answer
730

Views

Pygame, efficient collision handling for rpg game?

I'm currently programming a little Snes-like RPG with pygame. On my map I have 4 layers : 0 : Terrain, no collision (under char) 1 : Over Terrain no collision (under char) 2 : Collision objects (under char) 3 : Over char objects I wanted to create a rect for every tile in my second layer which wou...
Depado
1

votes
1

answer
1.3k

Views

How to put limits on resizing a window in pygame

I have a window in pygame set up like this: screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT),pygame.RESIZABLE) As you can see, it is resizable, and that aspect is working perfectly, but if it is too small, then you can not see everything, and so I would like to set up a limit, of for exa...
rp.beltran
1

votes
1

answer
193

Views

Why is my pygame sound file not playing? [closed]

My pygame game is not playing sound, I have tried to play it in several different ways. Could I get any help? bif="bg.bmp" mif="Male Hero.png" import os, sys import pygame, sys from pygame.locals import * pygame.init() pygame.mixer.pre_init(44100, -16, 2, 2048) walk = pygame.mixer.Sound(os.path.join...
user2700826
1

votes
1

answer
1.2k

Views

Library not initialized in Python (pygame)

so I have a font that I create in a class function. I called this function many times in the code and it works perfectly, but one time when I call it it says: self.font = pygame.font.Font( None, self.text_size ) RuntimeError: Library not initialized I couldn't fix it! so a line before the self.font...
Ofek .T.

View additional questions