本文整理汇总了Python中pygame.display方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.display方法的具体用法?Python pygame.display怎么用?Python pygame.display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame
的用法示例。
在下文中一共展示了pygame.display方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_game
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def start_game(self):
load_music('start')
while True:
self.window.fill([0, 0, 0])
self.get_event()
len_enemy = len(TankGame.enemy_tank_list)
self.window.blit(
self.draw_text('敌方坦克*{0},我方生命值*{1},当前{2}关'.format(len_enemy, self.my_tank_lift, self.number)), (10, 10))
if len_enemy == 0:
self.creat_enemy_number += 10
self.number += 1
self.my_tank_lift += 1
self.creat_enemy(self.creat_enemy_number)
self.wall_list.clear()
self.creat_walls()
self.show_my_tank()
self.show_enemy_tank()
self.show_bullet(TankGame.enemy_bullet_list)
self.show_bullet(TankGame.my_bullet_list)
self.show_walls()
self.display.update()
time.sleep(0.02)
示例2: display_image
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def display_image(display, image, window_size=(800, 600), blend=False):
"""Displays the given image on a pygame window
:param blend: whether to blend or not the given image.
:param window_size: the size of the pygame's window. Default is (800, 600)
:param display: pygame.display
:param image: the image (numpy.array) to display/render on.
"""
# Resize image if necessary
if (image.shape[1], image.shape[0]) != window_size:
image = resize(image, size=window_size)
image_surface = pygame.surfarray.make_surface(image.swapaxes(0, 1))
if blend:
image_surface.set_alpha(100)
display.blit(image_surface, (0, 0))
示例3: cv2_grayscale
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def cv2_grayscale(image, is_bgr=True, depth=1):
"""Convert a RGB or BGR image to grayscale using OpenCV (cv2).
:param image: input image, a numpy.ndarray.
:param is_bgr: tells whether the image is in BGR format. If False, RGB format is assumed.
:param depth: replicates the gray depth channel multiple times. E.g. useful to display grayscale images as rgb.
"""
assert depth >= 1
if is_bgr:
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
else:
grayscale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
if depth > 1:
return np.stack((grayscale,) * depth, axis=-1)
return grayscale
示例4: thread_grab_frames
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def thread_grab_frames(queue_frames, queue_poses):
win = pygame.Surface(win_size)
frame = pygame.Surface(img_size)
hmsurf = pygame.Surface(hmsurf_size)
screen = pygame.display.set_mode(screen_size)
while True:
get_frame(frame)
x = surface_to_array(win, frame)
queue_frames.put(x)
screen.blit(frame, (0,0))
pred = queue_poses.get()
# Unpack received data
x = pred[-1][0]
hm = pred[-2][0]
v = pred[-3]
p = pred[-4]
draw_pose(screen, p, v, img_size[0], img_size[1], prob_thr=0.7)
draw_heatmaps(screen, hmsurf, hm)
pygame.display.update()
示例5: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def __init__(self, filters=None):
"""Will init pygame.
Args:
filters (list): list of functions which takes and
returns a surface.
"""
pygame.init()
pygame.mouse.set_visible(False)
self.clock = pygame.time.Clock()
self.time_elapsed_milliseconds = 0
display_info = pygame.display.Info()
self.screen_size = (display_info.current_w, display_info.current_h)
self.screen = pygame.display.set_mode(self.screen_size,
FULLSCREEN | DOUBLEBUF)
self.filters = filters
示例6: update
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def update(self, surface):
"""Update the screen; apply surface to screen, automatically
rescaling for fullscreen.
"""
scaled_surface = pygame.transform.scale(surface, self.screen_size)
if self.filters:
for filter_function in self.filters:
scaled_surface = filter_function(scaled_surface)
self.screen.blit(scaled_surface, (0, 0))
pygame.display.flip()
self.time_elapsed_milliseconds = self.clock.tick(Screen.FPS)
# how much of this is redundant due to pygame Surface.scroll?
示例7: render_image
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def render_image(self, image):
"""
Render the given image to the pygame window
:param image: a grayscale or color image in an arbitrary size. assumes that the channels are the last axis
:return: None
"""
if self.is_open:
if len(image.shape) == 2:
image = np.stack([image] * 3)
if len(image.shape) == 3:
if image.shape[0] == 3 or image.shape[0] == 1:
image = np.transpose(image, (1, 2, 0))
surface = pygame.surfarray.make_surface(image.swapaxes(0, 1))
surface = pygame.transform.scale(surface, self.size)
self.screen.blit(surface, (0, 0))
self.display.flip()
self.clock.tick()
self.get_events()
示例8: todo_test_flip
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_flip(self):
# __doc__ (as of 2008-08-02) for pygame.display.flip:
# pygame.display.flip(): return None
# update the full display Surface to the screen
#
# This will update the contents of the entire display. If your display
# mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this
# will wait for a vertical retrace and swap the surfaces. If you are
# using a different type of display mode, it will simply update the
# entire contents of the surface.
#
# When using an pygame.OPENGL display mode this will perform a gl buffer swap.
self.fail()
示例9: test_set_caption
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def test_set_caption(self):
# __doc__ (as of 2008-08-02) for pygame.display.set_caption:
# pygame.display.set_caption(title, icontitle=None): return None
# set the current window caption
#
# If the display has a window title, this function will change the
# name on the window. Some systems support an alternate shorter title
# to be used for minimized displays.
#
TEST_CAPTION = "test"
screen = display.set_mode((100, 100))
self.assertIsNone(display.set_caption(TEST_CAPTION))
self.assertEqual(display.get_caption()[0], TEST_CAPTION)
self.assertEqual(display.get_caption()[1], TEST_CAPTION)
示例10: todo_test_get_driver
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_get_driver(self):
# __doc__ (as of 2008-08-02) for pygame.display.get_driver:
# pygame.display.get_driver(): return name
# get the name of the pygame display backend
#
# Pygame chooses one of many available display backends when it is
# initialized. This returns the internal name used for the display
# backend. This can be used to provide limited information about what
# display capabilities might be accelerated. See the SDL_VIDEODRIVER
# flags in pygame.display.set_mode() to see some of the common
# options.
#
self.fail()
示例11: todo_test_get_wm_info
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_get_wm_info(self):
# __doc__ (as of 2008-08-02) for pygame.display.get_wm_info:
# pygame.display.get_wm_info(): return dict
# Get information about the current windowing system
#
# Creates a dictionary filled with string keys. The strings and values
# are arbitrarily created by the system. Some systems may have no
# information and an empty dictionary will be returned. Most platforms
# will return a "window" key with the value set to the system id for
# the current display.
#
# New with pygame 1.7.1
self.fail()
示例12: todo_test_gl_set_attribute
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_gl_set_attribute(self):
# __doc__ (as of 2008-08-02) for pygame.display.gl_set_attribute:
# pygame.display.gl_set_attribute(flag, value): return None
# request an opengl display attribute for the display mode
#
# When calling pygame.display.set_mode() with the pygame.OPENGL flag,
# Pygame automatically handles setting the OpenGL attributes like
# color and doublebuffering. OpenGL offers several other attributes
# you may want control over. Pass one of these attributes as the flag,
# and its appropriate value. This must be called before
# pygame.display.set_mode()
#
# The OPENGL flags are;
# GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE,
# GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE,
# GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO
self.fail()
示例13: todo_test_iconify
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_iconify(self):
# __doc__ (as of 2008-08-02) for pygame.display.iconify:
# pygame.display.iconify(): return bool
# iconify the display surface
#
# Request the window for the display surface be iconified or hidden.
# Not all systems and displays support an iconified display. The
# function will return True if successfull.
#
# When the display is iconified pygame.display.get_active() will
# return False. The event queue should receive a ACTIVEEVENT event
# when the window has been iconified.
#
self.fail()
示例14: todo_test_set_gamma
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_set_gamma(self):
# __doc__ (as of 2008-08-02) for pygame.display.set_gamma:
# pygame.display.set_gamma(red, green=None, blue=None): return bool
# change the hardware gamma ramps
#
# Set the red, green, and blue gamma values on the display hardware.
# If the green and blue arguments are not passed, they will both be
# the same as red. Not all systems and hardware support gamma ramps,
# if the function succeeds it will return True.
#
# A gamma value of 1.0 creates a linear color table. Lower values will
# darken the display and higher values will brighten.
#
self.fail()
示例15: todo_test_set_icon
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import display [as 别名]
def todo_test_set_icon(self):
# __doc__ (as of 2008-08-02) for pygame.display.set_icon:
# pygame.display.set_icon(Surface): return None
# change the system image for the display window
#
# Sets the runtime icon the system will use to represent the display
# window. All windows default to a simple pygame logo for the window
# icon.
#
# You can pass any surface, but most systems want a smaller image
# around 32x32. The image can have colorkey transparency which will be
# passed to the system.
#
# Some systems do not allow the window icon to change after it has
# been shown. This function can be called before
# pygame.display.set_mode() to create the icon before the display mode
# is set.
#
self.fail()