pygame-surface

How to draw a transparent image in pygame?

允我心安 提交于 2019-12-10 16:46:53
问题 Consider a chess board, i have a transparent image of queen(queen.png) of size 70x70 and i want to display it over a black rectangle. Code: BLACK=(0,0,0) queen = pygame.image.load('queen.png') pygame.draw.rect(DISPLAYSURF, BLACK, (10, 10, 70, 70)) DISPLAYSURF.blit(queen, (10, 10)) Error: i am not getting transparent image ie black rectangle is not visible at all, only queen with white background. Please suggest 回答1: Try changing the line where you load in the queen to: queen = pygame.image

Start event when button is clicked with pygame

给你一囗甜甜゛ 提交于 2019-12-04 07:03:37
问题 Hey guys am new to pygame.I have developed a simple game in which the ball bounce each other.It works fine. I have added a ui with buttons with options like new game , loadgame , options . What I need is that when a user click on new game button he must see the ball bouncing. My code is import pygame import math from itertools import cycle def magnitude(v): return math.sqrt(sum(v[i]*v[i] for i in range(len(v)))) def add(u, v): return [ u[i]+v[i] for i in range(len(u)) ] def sub(u, v): return

How do I center a surface (subsurface) around a rectangle? (scaled sprite hitbox / collision rect)

旧巷老猫 提交于 2019-11-28 02:11:50
Currently I have working code which will cycle through a spritesheet, adding each cell/image (9 in total) as a subsurface into a list. As the game updates, I am setting the Player image as the current cell in which the code has indexed by. Meanwhile, I also have a set rectangle which acts as the sprites 'hitbox'/collision rect. However, setting the subsurface as the new image, I found that the sprite scales from the top-left corner of the collision rect. As the sprite is significantly larger than the collision rect, the collision rect is placed far away from the actual char model/sprite. I am

How do I center a surface (subsurface) around a rectangle? (scaled sprite hitbox / collision rect)

萝らか妹 提交于 2019-11-26 23:42:03
问题 Currently I have working code which will cycle through a spritesheet, adding each cell/image (9 in total) as a subsurface into a list. As the game updates, I am setting the Player image as the current cell in which the code has indexed by. Meanwhile, I also have a set rectangle which acts as the sprites 'hitbox'/collision rect. However, setting the subsurface as the new image, I found that the sprite scales from the top-left corner of the collision rect. As the sprite is significantly larger