本文整理匯總了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