Questions tagged [pygame-surface]

pygame object for representing images. Use this tag only if you are using the pygame library and not if you have a question about programming a game in python in general.

The most important part of pygame is the surface. Just think of a surface as a blank piece of paper. You can do a lot of things with a surface – you can draw lines on it, fill parts of it with color, copy images to and from it, and set or read individual pixel colors on it. A surface can be any size (within reason) and you can have as many of them as you like (again, within reason). One surface is special – the one you create with pygame.display.set_mode(). This ‘display surface’ represents the screen; whatever you do to it will appear on the user’s screen. You can only have one of these – that’s an SDL limitation, not a pygame one.

Home Page: http://www.pygame.org/docs/ref/surface.html

609 questions
48
votes
6 answers

How do I rotate an image around its center using Pygame?

I had been trying to rotate an image around its center in using pygame.transform.rotate() but it's not working. Specifically the part that hangs is rot_image = rot_image.subsurface(rot_rect).copy(). I get the exception: ValueError: subsurface…
Miha
  • 501
  • 1
  • 4
  • 4
38
votes
5 answers

How do I detect collision in pygame?

I have made a list of bullets and a list of sprites using the classes below. How do I detect if a bullet collides with a sprite and then delete that sprite and the bullet? #Define the sprite class class Sprite: def __init__(self,x,y, name): …
Mike Schmidt
  • 945
  • 3
  • 12
  • 31
29
votes
10 answers

SVG rendering in a Pygame application. Prior to Pygame 2.0, Pygame did not support SVG. Then how did you load it?

In a Pygame application, I would like to render resolution-free GUI widgets described in SVG. How can I achieve this? (I like the OCEMP GUI toolkit, but it seems to be bitmap-dependent for its rendering.)
Pierre-Jean Coudert
  • 9,109
  • 10
  • 50
  • 59
17
votes
4 answers

Animated sprite from few images

I've been searching for some good tutorial about making simple sprite animation from few images in Python using Pygame. I still haven't found what I'm looking for. My question is simple: how to make an animated sprite from few images (for an…
lbartolic
  • 1,165
  • 2
  • 12
  • 24
13
votes
4 answers

How to create a pygame surface from a numpy array of float32?

I have a piece of code that works using my_surface = pygame.image.load('some_image.png') This returns a pygame surface. I'd like to use the same code everywhere else but instead pass in a numpy array. (Actually, I'm going to have an if statement…
onjre
  • 403
  • 1
  • 3
  • 13
9
votes
3 answers

How can I load an animated GIF and get all of the individual frames in Pygame?

First of all, sorry if this is a duplicate. The answers that I found either seemed irrelevant but perhaps I'm searching with the wrong keywords. What I'd like to do is to take an animated GIF and split it up into a list of frames. Basically,…
user4594444
  • 111
  • 1
  • 6
7
votes
1 answer

Pygame: Fill transparent areas of text with a color

I have several fonts that I would like to use that are basically outlines of letters, but the insides are transparent. How would I go about filling only the inside areas of these fonts with with a color? I suspect it would be using the special…
7
votes
4 answers

How to present numpy array into pygame surface?

I'm writing a code that part of it is reading an image source and displaying it on the screen for the user to interact with. I also need the sharpened image data. I use the following to read the data and display it in pyGame def…
Yotam
  • 10,295
  • 30
  • 88
  • 128
6
votes
2 answers

Pygame water physics not working as intended

So, I have been trying to implement water physics in pygame based on this tutorial https://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236 The issue is, when I implemented this code in pygame, the…
Evelyn
  • 192
  • 7
6
votes
2 answers

How to fix this DeprecationWarning

DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using int is deprecated, and may be removed in a future version of Python. win.blit(playerStand, (x, y)) DeprecationWarning: an integer is required (got…
Blazing_Sun
  • 93
  • 1
  • 1
  • 6
6
votes
1 answer

pygame surface.blits when using area argument

I am trying to use surface.blits with the area parameter to improve the performance of my code. When I use the area parameter for blits, I run into the following error: SystemError: <'method 'blits' of 'pygame.Surface' objects> returned a result…
BradMcDanel
  • 543
  • 3
  • 15
5
votes
1 answer

Why is my collision test always returning 'true' and why is the position of the rectangle of the image always wrong (0, 0)?

My collide_rect function isn't working properly. It always returns True, when it's not suppose to. I have tried looking on the internet but nothing is working for me. I think the collide rect somehow did not use the actual coordinates for the two…
aqua959
  • 99
  • 1
  • 14
5
votes
2 answers

Why is my program became really laggy after I added rotation, and how do I fix this?

I'm making a game using pygame, and I have an asteroid class. When I add rotation to the update method and I run the program, the asteroids move really slow and laggy, and even their images look worse then before. I am not sure how to fix this and…
Omer
  • 223
  • 1
  • 8
5
votes
1 answer

Python surface real position coordinates of pygame.mouse.get_pos and Rect.collidepoint

In my python prog i have 2 surfaces : ScreenSurface : the screen FootSurface : another surface blited on ScreenSurface. I put some rect blitted on the FootSurface, the problem is that Rect.collidepoint() gives me relative coordinates linked to the…
user3619937
  • 85
  • 2
  • 6
4
votes
1 answer

How to draw rectangle and circles in Pygame environment

I am trying to create a pygame environment with various shapes of sprites but my code seems not working. Here is what I have: class Object(pygame.sprite.Sprite): def __init__(self, position, color, size, type): # create square sprite …
jigz
  • 57
  • 4
1
2 3
40 41