首页 文章 Pygame Front Page

Pygame Front Page

2024-05-07 19:36  浏览数:565  来源:白可    

Pygame Front PageQuick startWelcome to pygame! Once you've got pygame installed (pip insta
ll pygame or pip3 install pygame for most people), the next question is how to get a game
loop running. Pygame, unlike some other libraries, gives you full control of program execu
tion. That freedom means it is easy to mess up in your initial steps.Here is a good exampl
e of a basic setup (opens the window, updates the screen, and handles events)--# Example f
ile showing a basic pygame "game loop"import pygame# pygame setuppygame.init()screen = pyg
ame.display.set_mode((1280, 720))clock = pygame.time.Clock()running = Truewhile running:
# poll for events # pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get(): if event.type == pygame.QUIT: running
= False # fill the screen with a color to wipe away anything from last frame screen
.fill("purple") # RENDER YOUR GAME HERE # flip() the display to put your work on scr
een pygame.display.flip() clock.tick(60) # limits FPS to 60pygame.quit()Here is a s
lightly more fleshed out example, which shows you how to move something (a circle in this
case) around on screen--# Example file showing a circle moving on screenimport pygame# pyg
ame setuppygame.init()screen = pygame.display.set_mode((1280, 720))clock = pygame.time.Clo
ck()running = Truedt = 0player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_hei
ght() / 2)while running: # poll for events # pygame.QUIT event means the user clicke
d X to close your window for event in pygame.event.get(): if event.type == pygam
e.QUIT: running = False # fill the screen with a color to wipe away anything
from last frame screen.fill("purple") pygame.draw.circle(screen, "red", player_pos,
40) keys = pygame.key.get_pressed() if keys[pygame.K_w]: player_pos.y -= 300
* dt if keys[pygame.K_s]: player_pos.y += 300 * dt if keys[pygame.K_a]:
player_pos.x -= 300 * dt if keys[pygame.K_d]: player_pos.x += 300 * dt # f
lip() the display to put your work on screen pygame.display.flip() # limits FPS to 6
0 # dt is delta time in seconds since last frame, used for framerate- # independent
physics. dt = clock.tick(60) / 1000pygame.quit()For more in depth reference, check out
the Tutorials section below, check out a video tutorial (I'm a fan of this one), or refere
nce the API documentation by module.DocumentsReadmeBasic information about pygame: what it
is, who is involved, and where to find it.InstallSteps needed to compile pygame on severa
l platforms. Also help on finding and installing prebuilt binaries for your system.File Pa
th Function ArgumentsHow pygame handles file system paths.Pygame LogosThe logos of Pygame
in different resolutions.LGPL LicenseThis is the license pygame is distributed under. It p
rovides for pygame to be distributed with open source and commercial software. Generally,
if pygame is not changed, it can be used with any type of program.TutorialsIntroduction to
PygameAn introduction to the basics of pygame. This is written for users of Python and ap
peared in volume two of the Py magazine.Import and InitializeThe beginning steps on import
ing and initializing pygame. The pygame package is made of several modules. Some modules a
re not included on all platforms.How do I move an Image?A basic tutorial that covers the c
oncepts behind 2D computer animation. Information about drawing and clearing objects to ma
ke them appear animated.Chimp Tutorial, Line by LineThe pygame examples include a simple p
rogram with an interactive fist and a chimpanzee. This was inspired by the annoying flash
banner of the early 2000s. This tutorial examines every line of code used in the example.S
prite Module IntroductionPygame includes a higher level sprite module to help organize gam
es. The sprite module includes several classes that help manage details found in almost al
l games types. The Sprite classes are a bit more advanced than the regular pygame modules,
and need more understanding to be properly used.Surfarray IntroductionPygame used the Num
Py python module to allow efficient per pixel effects on images. Using the surface arrays
is an advanced feature that allows custom effects and filters. This also examines some of
the simple effects from the pygame example, arraydemo.py.Camera Module IntroductionPygame,
as of 1.9, has a camera module that allows you to capture images, watch live streams, and
do some basic computer vision. This tutorial covers those use cases.Newbie GuideA list of
thirteen helpful tips for people to get comfortable using pygame.Making Games TutorialA l
arge tutorial that covers the bigger topics needed to create an entire game.Display ModesG
etting a display surface for the screen.한국어 튜토리얼 (Korean Tutorial)빨간블록 검은블록ReferenceIndexA
list of all functions, classes, and methods in the pygame package.pygame.BufferProxyAn ar
ray protocol view of surface pixelspygame.ColorColor representation.pygame.cursorsLoading
and compiling cursor images.pygame.displayConfigure the display surface.pygame.drawDrawing
simple shapes like lines and ellipses to surfaces.pygame.eventManage the incoming events
from various input devices and the windowing platform.pygame.examplesVarious programs demo
nstrating the use of individual pygame modules.pygame.fontLoading and rendering TrueType f
onts.pygame.freetypeEnhanced pygame module for loading and rendering font faces.pygame.gfx
drawAnti-aliasing draw functions.pygame.imageLoading, saving, and transferring of surfaces
.pygame.joystickManage the joystick devices.pygame.keyManage the keyboard device.pygame.lo
calsPygame constants.pygame.mixerLoad and play soundspygame.mouseManage the mouse device a
nd display.pygame.mixer.musicPlay streaming music tracks.pygameTop level functions to mana
ge pygame.pygame.PixelArrayManipulate image pixel data.pygame.RectFlexible container for a
rectangle.pygame.scrapNative clipboard access.pygame.sndarrayManipulate sound sample data
.pygame.spriteHigher level objects to represent game images.pygame.SurfaceObjects for imag
es and the screen.pygame.surfarrayManipulate image pixel data.pygame.testsTest pygame.pyga
me.timeManage timing and framerate.pygame.transformResize and move images.pygame C APIThe
C api shared amongst pygame extension modules.Search PageSearch pygame documents by keywor
d.



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)