pygame

python 播放MP3和MP4

对着背影说爱祢 提交于 2020-12-06 14:00:13
import pygame import time def play_music(): filepath = r " 900A.mp3 " ; pygame.mixer.init() # 加载音乐 pygame.mixer.music.load(filepath) pygame.mixer.music.play(start =0.0 ) # 播放时长,没有此设置,音乐不会播放,会一次性加载完 time.sleep(300 ) pygame.mixer.music.stop() play_music() MP4 class Video(object): def __init__ (self,path): self.path = path def play(self): from os import startfile startfile(self.path) class Movie_MP4(Video): type = ' MP4 ' movie = Movie_MP4(r ' F:\Y2019\Python\ppt\ArcGIS Python入门到精通广告视频.mp4 ' ) movie.play() 来源: oschina 链接: https://my.oschina.net/u/4287611/blog/3329457

使用 GIMP 轻松地设置图片透明度

梦想与她 提交于 2020-12-02 22:11:07
使用色键(或绿屏)技巧来设置你电脑游戏中图片的透明度。 不管你是否正在使用 Python 或 Lua 编程一个游戏或一个 APP,你都有可能在你的游戏资源中使用 PNG 图像。PNG 格式图像的一个优点是能够存储一个 alpha 通道 ,这在一个 JPEG 格式的图像中是不可能获得的。alpha 在本质上是不可见的或透明的“颜色”。alpha 是你图像 不可见 的一部分。例如,你要绘制一个甜甜圈,甜甜圈的空洞将使用 alpha 填充,你就可以看到它后面的任何东西。 一个常见的问题是如何找到一幅图像的 alpha 部分。有时你的编程框架,不管它是 Python Arcade 、 Pygame 、LÖVE,或者其它的任何东西都会检测出 alpha 通道,(在适当地调用函数后)将其作为透明处理。这意味着它将不会在 alpha 部分来渲染新的像素,而留下甜甜圈的空洞。100% 是透明的,0% 是不透明的,在功能上起到“不可见”的作用。 有些时候,你的框架与你的图像资源在 alpha 通道的位置上是不一致的(或者,alpha 通道根本就不存在),你在你想要透明度的地方却得到像素。 这篇文章描述了我所知道的最可靠的方法来解决透明度的问题。 色键 在计算机图形学中,有一些有助于确定每一个像素是如何渲染的值。色度Chrominance(或者 chroma),描述一个像素的饱和度或强度

Pygame Drawing a Rectangle

心已入冬 提交于 2020-12-02 06:05:06
问题 Im making a game that requires knowing how to draw a rectangle in python 3.2. I have checked lot of sources but none show exactly how to do it. Thanks! 回答1: import pygame, sys from pygame.locals import * def main(): pygame.init() DISPLAY=pygame.display.set_mode((500,400),0,32) WHITE=(255,255,255) BLUE=(0,0,255) DISPLAY.fill(WHITE) pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50)) while True: for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.display.update()

Pygame Drawing a Rectangle

早过忘川 提交于 2020-12-02 06:00:48
问题 Im making a game that requires knowing how to draw a rectangle in python 3.2. I have checked lot of sources but none show exactly how to do it. Thanks! 回答1: import pygame, sys from pygame.locals import * def main(): pygame.init() DISPLAY=pygame.display.set_mode((500,400),0,32) WHITE=(255,255,255) BLUE=(0,0,255) DISPLAY.fill(WHITE) pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50)) while True: for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.display.update()

Pygame Drawing a Rectangle

拟墨画扇 提交于 2020-12-02 06:00:22
问题 Im making a game that requires knowing how to draw a rectangle in python 3.2. I have checked lot of sources but none show exactly how to do it. Thanks! 回答1: import pygame, sys from pygame.locals import * def main(): pygame.init() DISPLAY=pygame.display.set_mode((500,400),0,32) WHITE=(255,255,255) BLUE=(0,0,255) DISPLAY.fill(WHITE) pygame.draw.rect(DISPLAY,BLUE,(200,150,100,50)) while True: for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.display.update()

Pygame snake velocity too high when the fps above 15 [duplicate]

泪湿孤枕 提交于 2020-11-29 11:16:16
问题 This question already has an answer here : Framerate affect the speed of the game (1 answer) Closed last month . I am having a hard time figuring the physics of speed in this snake game I made using pygame. The issue is that as soon as I set the fps to be above 15, the snake's speed increases as well. I know that this has to do with milliseconds etc which I found to work, high fps with slow speed. However at that point, I could not get the X and Y to be correct so that I can eat the apple. I

Creating multiple sprites with different update()'s from the same sprite class in Pygame

给你一囗甜甜゛ 提交于 2020-11-29 11:00:07
问题 I'm trying to make multiple sprites that all come from the same pygame sprite class. class animatedSprites(pygame.sprite.Sprite): def __init__(self, spriteName): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface((width,height)) self.images = [] self.images.append(spriteName[0]) self.rect = self.image.get_rect() #sets sprites size and pos self.rect.center = (POSITIONx1[4], POSITIONy1[4]) self.animation_frames = 12 self.current_frame = 0 self.previous_positiony = self.rect.y self

Problem with Pygame movement acceleration, platformer game [duplicate]

可紊 提交于 2020-11-29 10:22:25
问题 This question already has answers here : Pygame doesn't let me use float for rect.move, but I need it (2 answers) Closed 7 days ago . When i move right using the right key, i accelerate to a max speed. When i release it, i do decelerate to a stop so that is fine. However, when moving left using the left key, and after releasing it, i continue moving at a fixed speed and then come to an abrupt stop after a short while. Any idea what could be wrong with my code? The original code is from http:/

Problem with Pygame movement acceleration, platformer game [duplicate]

我的梦境 提交于 2020-11-29 10:22:22
问题 This question already has answers here : Pygame doesn't let me use float for rect.move, but I need it (2 answers) Closed 7 days ago . When i move right using the right key, i accelerate to a max speed. When i release it, i do decelerate to a stop so that is fine. However, when moving left using the left key, and after releasing it, i continue moving at a fixed speed and then come to an abrupt stop after a short while. Any idea what could be wrong with my code? The original code is from http:/

How can i shoot a bullet with space bar?

南笙酒味 提交于 2020-11-29 09:43:49
问题 Heres my code import pygame, os os.environ["SDL_VIDEO_CENTERED"] = "1" pygame.init() win = pygame.display d = win.set_mode((1200, 600)) class player: def __init__(self, x, y, height, width): self.x = x self.y = y self.height = height self.width = width self.speed = 2 def draw(self): pygame.draw.rect(d, (0, 0, 0), (self.x, self.y, self.width, self.height)) def move_left(self): self.x -= self.speed def move_right(self): self.x += self.speed class bullet: def __init__(self): self.radius = 10