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

TypeError: invalid destination position for blit

Please help. I've been searching but i still don't quite grasp how to fix the problem. I don't know if i;m forgetting something or the values of x and y are not considered int's for some reason (i have put in past tries to fix it: int(x)) I want to…
3
votes
1 answer

Sprites not showing in Pygame

I'm not sure what I am doing wrong here. There are no errors appearing but when the game loads nothing appears, just the black background. This is the code that I am running for loading my sprite into the game. import pygame import sys import…
S V
  • 31
  • 4
3
votes
0 answers

How to fix OOP Issue with opacity change in pygame

I'm trying to make pieces of what makes pygame into it's own separate classes/definitions. But when trying to set the opacity of an image, Instead of showing up as excepted, It starts from it's set opacity and lightens up until it reaches the…
3
votes
1 answer

Pygame Combine Sprites

I am trying to build a game in which combining images (pygame sprites) is an essential tool. I have set up my code such that I can move sprites across x,y with the mouse and rotate them. The sprites are blitted to the display surface and so this…
Didgeridude
  • 123
  • 6
3
votes
1 answer

Getting the name of variables in a list

I want to get the name of the variable in a list with the index. For example: a = 1 b = 2 list = [a, b] print(list[0]) and the output is 1 Is there a way to get "a" as a String instead of 1? Also, the above code is just an example. I am coding…
Coco Liliace
  • 311
  • 5
  • 14
3
votes
1 answer

How do I pass a rect into pygame.display.update() to update a specific area of the window?

On the documentation page for pygame.display.update(), it says you can pass a rect into the method to update part of the screen. However, all of the examples I see just pass an existing rect from an image or shape in the program. How can I tell it…
Johnny Dollard
  • 708
  • 3
  • 11
  • 26
3
votes
1 answer

Blitting non-rectangular sprites with Pygame, Python 3

I'm currently making a game, in which I load the sprites and backgrounds from images (PNG) using the pygame.image.load() function. My problem is that not all of my sprites are rectangular - and because of that they leave ugly white-space on the…
Vladimir Shevyakov
  • 2,511
  • 4
  • 19
  • 40
3
votes
1 answer

Pygame creating surfaces

Code: #!/usr/bin/python import pygame, time, sys, random, os from pygame.locals import * from time import gmtime, strftime pygame.init() w = 640 h = 400 screen = pygame.display.set_mode((w, h),RESIZABLE) clock = pygame.time.Clock() x = y =…
Yubin Lee
  • 814
  • 2
  • 9
  • 26
3
votes
1 answer

How do I add a line as a sprite in pygame?

I want to add a grid to my level that stays with the terrain and not the screen. The way I thought of doing it is to add all the lines that form the grid as sprites and move them with the terrain, but I can't figure out how to represent the line as…
Alexdr5398
  • 51
  • 1
  • 6
2
votes
1 answer

pygame doesn't rotate surface

import pygame WIDTH, HEIGHT = 1024, 768 pygame.init() WIN = pygame.display.set_mode((WIDTH, HEIGHT)) skala = pygame.image.load("rock2x3b.jpg") play = True if __name__ == "__main__": FPS = 60 clock = pygame.time.Clock() square =…
Steve1478
  • 21
  • 2
2
votes
1 answer

Moving pygame surface doesn't move thorpy buttons

I'm working on a Pygame project using Thorpy for GUI elements. I've created Thorpy buttons attached to a Pygame surface. When I move the surface using the blit function, the visual representation of the buttons moves, but their hitboxes remain…
2
votes
1 answer

Boids Algorithm. pygame.Rect shape not displayed properly in the window

I am trying to rewrite some code to take advantage of pygame sprites in Boids Algorithm implementation. Currently the goal is to create multiple sprites on screen (number determined by "flock" variable) and get them moving in random directions,…
2
votes
2 answers

Pygame sprite instance affects position of another sprite class

I am creating a type Space Invader game, with a ship which can fire a bullet from its position, with direction velocity. When I create a bullet from key input, the update method in Bullet affects the Players position and velocity as well, almost as…
marloop007
  • 21
  • 4
2
votes
1 answer

Im trying to make a fade in and out

I am trying to create a function that will fade in and out for a game that I'm making. the problem is that the first part works fine but the second pard doesn't work. WIDTH = screen width, HEIGHT = screen height, WINDOW = the name of the window, and…
LStep
  • 87
  • 5
2
votes
1 answer

How do I animate a pygame screen using classes, functions, and a for loop?

I'm throwing myself at the mercy of the SO community, having looked at the below now for considerable time. I'm attempting to create an animated background for my title screen which loops through eight elements in a list called background_images. By…
Rahman
  • 21
  • 4