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
2
votes
1 answer

How would I make color collision using pygame.mask?

I prepared a few hitboxes around certain enemies. These hitboxes are white. When they come into contact with a certain color, for example, red, it would trigger an if statement. I have heard pygame.mask is useful in this situation. The Code: #…
hmood
  • 603
  • 7
  • 25
2
votes
1 answer

Why won't my Spaceship point toward the planet?

Small gif showing problem but I don't have 10 reputation yet (this is only my 2nd question) and thus have to use link I have a simple test program with a Spaceship which is supposed to point toward a planet, but it points in odd directions…
2
votes
1 answer

Pygame Surface.set_at is setting alpha to 255?

I have this code: import pygame, sys pygame.init() screen = pygame.display.set_mode([640,480]) screen.fill([100,100,100]) pygame.display.flip() image = pygame.image.load("tree.png").convert_alpha() surf = pygame.Surface([1024,1024]) for y in…
TheDude04
  • 107
  • 9
2
votes
1 answer

PYGAME : Why does calling a function inside the game loop inside Game loop make my game lag?

I am making a simple game where enemies move around on the screen and we need to shoot them.I wanted to modularize my code so I wanted to replace the game loop logic with a function.But as soon as I do that, there's a drop in fps. Does calling a…
Savannah Madison
  • 575
  • 3
  • 8
  • 17
2
votes
1 answer

Surface display able to properly represent opacity, but any other surface cannot

I am trying to make a tic-tac-toe game with pygame. An important thing I want is being able to make my images (eg. X and O) slightly translucent for when my user is only hovering over a grid tile. I also use opacity to visually show whose turn it…
MaxwellN
  • 707
  • 1
  • 5
  • 13
2
votes
1 answer

How can I move the ball instead of leaving a trail all over the screen in pygame?

I'm building a pong game trying to get better at programming but Im having trouble moving the ball. When the move_right method is called the ellipse stretches to the right instead of moving to the right. I've tried putting the ball variable in the…
2
votes
1 answer

How can you draw more detailed/smoother images in pygame?

I have been trying to get into the vector-styled art world and recently I've tried blitting a vector image using the .blit() method but when I do blit it, it comes out as pixelated. Here is the image: and here is how it looks in pygame with the…
Yawn
  • 71
  • 7
2
votes
1 answer

cannot create surface even though it seems correct

self.image = pygame.Surface( int(math.sqrt((end_pos[1] - start_pos[1])**2 +(end_pos[0] - start_pos[0])**2)), width) returns the error: ValueError: size needs to be (int width, int height)
aadnnn1
  • 53
  • 1
  • 4
2
votes
1 answer

How to get text width in pygame?

if score == 10: myFont = pygame.font.SysFont("times new roman ", 35) white = (255,255,255) text2 = ("You win! Congrats!") label2 = myFont.render(text2, 1, white) text_width = text2.get_width() screen.blit(label2, (text2_width,…
2
votes
2 answers

How to update text appearing on button click in pygame module

I was making a code where on clicking a button, a string will be chosen randomly from myList and be displayed. I am doing this using pygame module. The problem here is that the text does not remain, it just flashes for one frame. Here's the…
MansiCodes
  • 25
  • 5
2
votes
1 answer

Why is my Pygame sprite rotating like a collision box?

Right, so this is out of all the questions and bugs I have had in Python/Pygame, the strangest one to me. So I just learned how to rotate something in Pygame and it was working fine with everything else except this one sprite. This is what rotates…
Duck Duck
  • 159
  • 6
2
votes
1 answer

How to zoom in and out of an image pygame and using the mousposition as the center of the zoom

I am having an issue with PyGame i can't resolve. So: my idea is that I have a map I can zoom in/out on. zooming in works fine. But zooming out shows that the rest of the picture got deleted and only the part of the image that was previously visible…
2
votes
1 answer

I can't draw a filled rectangle

I am trying to draw a screen with a filled in box in the center. I am using pygame.Surface.fill() for the box but it gives this error: TypeError: descriptor 'fill' for 'pygame.Surface' objects doesn't apply to a 'tuple' object Here is my…
Shark Coding
  • 143
  • 1
  • 10
2
votes
1 answer

Error pygame: Argument must be a sequence of rectstyle objects

Hi I'm trying to make a simple 2d car game with pygame and I'm trying to add collisions between two cars, but i keep getting this error: Traceback (most recent call last): File "C:\Users\emilio pinto\Desktop\Running car proj\Running car.py", line…
Emilio P.
  • 23
  • 2
2
votes
2 answers

Collision detection between pygame.Surface and mouse not working

I am trying to make a canvas for pixel art. class Canvas: def __init__(self): self.__blocks = [] self.__positions = [] for i in range(1830): self.__blocks.append(pygame.Surface((20, 20)).convert()) for…
user12291970