本文整理汇总了Python中pygame.draw方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.draw方法的具体用法?Python pygame.draw怎么用?Python pygame.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame
的用法示例。
在下文中一共展示了pygame.draw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_draw_labels
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def test_draw_labels(scene):
"""We can draw text labels."""
scene.background = '#ccccff'
scene.layers[0].add_label(
"Left\naligned.",
pos=(10, 50),
color='navy'
)
scene.layers[0].add_label(
"or right",
font="eunomia_regular",
fontsize=60,
pos=(790, 200),
align="right",
color=(0.5, 0, 0),
)
scene.layers[0].add_label(
"Center über alles",
fontsize=40,
pos=(400, 500),
align="center",
color='black',
)
示例2: test_draw_sprite
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def test_draw_sprite(scene):
"""We can draw a sprite to the scene."""
scene.layers[0].add_sprite('ship', pos=(400, 300))
示例3: _draw_base
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def _draw_base(self):
"""
Widgets should overload to draw default images found in self._images.
This method will not be called when the user gives a custom image.
"""
pass
示例4: _draw_final
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def _draw_final(self):
"""
Widgets should overload to draw final things that should
be drawn regardless of whether a custom image was used or not.
"""
pass
示例5: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def __init__(self, **kwargs):
"""初始化
可选参数:
game_name 游戏名称
icon 图标文件名
screen_size 画面大小
display_mode 显示模式
loop_speed 主循环速度
font_name 字体文件名
font_size 字体大小
"""
pygame.init()
pygame.mixer.init()
self.game_name = kwargs.get("game_name") or GAME_NAME
pygame.display.set_caption(self.game_name)
self.screen_size = kwargs.get("screen_size") or SCREEN_SIZE
self.screen_width, self.screen_height = self.screen_size
self.display_mode = kwargs.get("display_mode") or DISPLAY_MODE
self.images = {}
self.sounds = {}
self.musics = {}
self.icon = kwargs.get("icon") or None
self.icon and pygame.display.set_icon(pygame.image.load(self.icon))
self.screen = pygame.display.set_mode(self.screen_size,
self.display_mode)
self.loop_speed = kwargs.get("loop_speed") or LOOP_SPEED
self.font_name = kwargs.get("font_name") or FONT_NAME
self.font_size = kwargs.get("font_size") or FONT_SIZE
self.font = pygame.font.Font(self.font_name, self.font_size)
self.clock = pygame.time.Clock()
self.now = 0
self.background_color = kwargs.get("background") or BLACK
self.set_background()
self.key_bindings = {} # 按键与函数绑定字典
self.add_key_binding(KEY_PAUSE, self.pause)
self.game_actions = {} # 游戏数据更新动作
self.draw_actions = [self.draw_background] # 画面更新动作列表
self.running = True
self.draw = pygame.draw
示例6: test_draw_many_sprites
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import draw [as 别名]
def test_draw_many_sprites(scene):
"""Test that we can draw hundreds of large sprites.
We want to test that we grow the available texture space when necessary, so
we generate and pre-cache new sprites.
"""
scene.layers[1].add_sprite('ship', pos=(400, 300))
rng = random.Random(0)
with patch.dict(images.__dict__, _cache={}):
for i in range(100):
s = Surface((64, 64), flags=pygame.SRCALPHA, depth=32)
segments = rng.randint(6, 9)
theta = np.linspace(0, 2 * np.pi, segments).reshape((-1, 1))
verts = np.hstack([
np.cos(theta),
np.sin(theta),
]).astype('f4')
radii = np.array([rng.uniform(10, 30) for _ in verts])
verts *= radii[:, np.newaxis]
verts += (32, 32)
color = np.array((rng.randint(128, 200),) * 3, dtype=np.uint8)
pygame.draw.polygon(
s,
points=verts,
color=color
)
pygame.draw.polygon(
s,
points=verts,
color=color // 2,
width=2,
)
k = f'rock{i}'
images._cache[k, (), ()] = s
scene.layers[0].add_sprite(
k,
pos=(
rng.uniform(0, 800),
rng.uniform(0, 600),
)
)
assert len(scene.layers.atlas.packer.texs) > 1