当前位置: 首页>>代码示例>>Python>>正文


Python pygame.draw方法代码示例

本文整理汇总了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',
    ) 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:25,代码来源:test_sprites.py

示例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)) 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:5,代码来源:test_sprites.py

示例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 
开发者ID:furas,项目名称:python-examples,代码行数:9,代码来源:base_widget.py

示例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 
开发者ID:furas,项目名称:python-examples,代码行数:9,代码来源:base_widget.py

示例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 
开发者ID:archtaurus,项目名称:pysnake,代码行数:45,代码来源:mygame.py

示例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 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:45,代码来源:test_sprites.py


注:本文中的pygame.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。