pygame-surface

How to turn the sprite in pygame while moving with the keys

拟墨画扇 提交于 2020-12-23 12:17:13
问题 So basically ive been hoping it would be possible to effectively turn your sprite while moving it around with W A S D . Any ideas because im certainly stumped, thanks! 回答1: See How do I rotate an image around its center using PyGame? for rotating a surface. If you want to rotate an image around a center point ( cx , cy ) you can just do that: rotated_car = pygame.transform.rotate(car, angle) window.blit(rotated_car, rotated_car.get_rect(center = (cx, cy)) Use pygame.math.Vector2 to store the

How to turn the sprite in pygame while moving with the keys

放肆的年华 提交于 2020-12-23 12:14:51
问题 So basically ive been hoping it would be possible to effectively turn your sprite while moving it around with W A S D . Any ideas because im certainly stumped, thanks! 回答1: See How do I rotate an image around its center using PyGame? for rotating a surface. If you want to rotate an image around a center point ( cx , cy ) you can just do that: rotated_car = pygame.transform.rotate(car, angle) window.blit(rotated_car, rotated_car.get_rect(center = (cx, cy)) Use pygame.math.Vector2 to store the

How do I convert an OpenCV (cv2) image (BGR and BGRA) to a pygame.Surface object

∥☆過路亽.° 提交于 2020-12-19 04:25:08
问题 I created images from OpenCV/opencv-python (numpy.array) and I want to convert them to a pygame.Surface object: def cv2ImageToSurface(cv2Image): pygameSurface = # ? create from "cv2Image" return pygameSurface surface = cv2ImageToSurface(cv2Image) Some of the images have 3 channels ( BGR ) and some of the images also have an alpha channel ( BGRA ). What do I have to do in cv2ImageToSurface to convert images with one of the formats into a pygame.Surface object? 回答1: The shape attribute of a

How do I change the color of a button once it is clicked in Pygame?

倖福魔咒の 提交于 2020-12-16 07:00:42
问题 I have been working on this project, and I have created a selection screen with functions and events so that when the mouse hovers over a button it turns orange. But it being a selection screen, once a button is clicked I want it to stay highlighted to show that that item has being selected but I can't seem to figure out how to do this. Here is my code: def button2(msg,x,y,w,h,ic,ac, action=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if x+w > mouse[0] > x and y+h

How do I change the color of a button once it is clicked in Pygame?

99封情书 提交于 2020-12-16 07:00:41
问题 I have been working on this project, and I have created a selection screen with functions and events so that when the mouse hovers over a button it turns orange. But it being a selection screen, once a button is clicked I want it to stay highlighted to show that that item has being selected but I can't seem to figure out how to do this. Here is my code: def button2(msg,x,y,w,h,ic,ac, action=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if x+w > mouse[0] > x and y+h

How can I make an Image with a transparent Backround in Pygame?

微笑、不失礼 提交于 2020-12-13 03:24:07
问题 I am fairly new to programming, so I bought the Book "Python Crash Course" by Eric Matthes. Recently, I decided to recreate the Pokemon Battle System in Pygame. So far, I have made a good enough framework to start the battle system. I picked the Pokemon Mew as a test subject. I already have the transparent backround for the picture, but pygame still shows the gray and white squares. This is my main code-file: from settings import Settings def run_game(): pygame.init() ai_settings = Settings()

the car moves and changes direction when it hits the window edge [closed]

余生长醉 提交于 2020-12-13 03:18:41
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 days ago . Improve this question The car is moving straight. When it hits the window edge it moves backwards then changes direction at an angle of 45 degrees clockwise and keeps moving straight. if it hit the edge of the window again, it would do the same I've made the code below. I was only

the car moves and changes direction when it hits the window edge [closed]

落爺英雄遲暮 提交于 2020-12-13 03:18:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 days ago . Improve this question The car is moving straight. When it hits the window edge it moves backwards then changes direction at an angle of 45 degrees clockwise and keeps moving straight. if it hit the edge of the window again, it would do the same I've made the code below. I was only

the car moves and changes direction when it hits the window edge [closed]

孤人 提交于 2020-12-13 03:16:35
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 days ago . Improve this question The car is moving straight. When it hits the window edge it moves backwards then changes direction at an angle of 45 degrees clockwise and keeps moving straight. if it hit the edge of the window again, it would do the same I've made the code below. I was only

the car moves and changes direction when it hits the window edge [closed]

旧街凉风 提交于 2020-12-13 03:16:02
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 days ago . Improve this question The car is moving straight. When it hits the window edge it moves backwards then changes direction at an angle of 45 degrees clockwise and keeps moving straight. if it hit the edge of the window again, it would do the same I've made the code below. I was only