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


Python Label.delete方法代码示例

本文整理汇总了Python中pyglet.text.Label.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Label.delete方法的具体用法?Python Label.delete怎么用?Python Label.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.text.Label的用法示例。


在下文中一共展示了Label.delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Button

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
class Button(object):
    """docstring for Button"""
    def __init__(self, text, x, y, width, height, batch, color=(50, 50, 50),
                 scale=unity, **kwargs):
        super(Button, self).__init__()
        self.pos = vec2(x, y) * scale
        self.width = width * scale.x
        self.height = height * scale.y
        self.bsize = 2 * scale.x
        self.color = color
        self.hcolor = hcolor
        self.text = Label(text, x=(self.pos.x + self.width / 2),
                          y=(self.pos.y + self.height / 2),
                          anchor_x='center', anchor_y='center',
                          batch=batch, **kwargs)
        self.bound = Rect(self.pos.x - self.bsize, self.pos.y - self.bsize,
                          self.width+2*self.bsize, self.height+2*self.bsize,
                          color=toplinecolor, batch=batch)
        self.rect = Rect(self.pos.x, self.pos.y, self.width, self.height,
                         color=self.color, batch=batch)

    def highlight(self):
        self.rect.update_color(self.hcolor)

    def restore(self):
        if not self.rect.color == self.color:
            self.rect.update_color(self.color)

    def over_button(self, x, y):
        return (0 < x - self.pos.x < self.width and
                0 < y - self.pos.y < self.height)

    def delete(self):
        self.text.delete()
        self.rect.delete()
开发者ID:mokapharr,项目名称:python_game,代码行数:37,代码来源:elements.py

示例2: calculate

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
 def calculate(self):
     if self.name is None:
         return
     from pyglet.text import Label
     label = Label(self.text, self.name, self.size, self.bold, 
         self.italic, width = self.width)
     self.calculatedWidth = label.content_width
     self.calculatedHeight = label.content_height
     label.delete()
开发者ID:Matt-Esch,项目名称:anaconda,代码行数:11,代码来源:CalcRect.py

示例3: __init__

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
class FloatingCombatText:

    def __init__(
        self, ui, text, x, y, duration=1.,
        scale=1., second_scale=0.5, growth=0.2, velocity=75,
        color="darkred", batch=None
    ):
        self.start_scale = scale
        self.second_scale = second_scale
        self.growth = growth
        self.x, self.y = x, y
        self.ui = ui
        wx, wy = self.ui.window.get_windowpos(x, y)
        self.color = lookup_color(color)
        self.label = Label(
            text=str(text), font_name=None, font_size=12 * scale,
            x=wx, y=wy, anchor_x="center", anchor_y="center",
            color=self.color, batch=batch,
        )
        self.velocity = velocity
        self.timer = duration
        self.duration = duration
        self.done = False

    def on_end(self):
        self.label.delete()
        self.done = True

    def update(self, dt):
        if self.timer <= 0:
            self.on_end()
        else:
            self.timer -= dt
            perc = self.timer / self.duration
            scale = (
                self.second_scale + (
                    (self.start_scale - self.second_scale) * perc
                )
            )
            self.y += self.velocity * dt
            self.label.font_size = 9 * scale
            self.label.x, self.label.y = self.ui.window.get_windowpos(
                self.x, self.y, precise=True
            )
            opacity = int(255 * perc)
            if opacity < 0:
                opacity = 0
            self.color = self.color[0], self.color[1], self.color[2], opacity
            self.label.color = self.color
开发者ID:NiclasEriksen,项目名称:rpg_procgen,代码行数:51,代码来源:ui.py

示例4: HudTitle

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
class HudTitle(GameItem):

    render_layer = 3

    def __init__(self):
        GameItem.__init__(self)
        self.titleLabel = None
        self.pressAnyKeyLabel = None


    def add_to_batch(self, batch, groups):
        self.titleLabel = Label(
            'Sinister Ducks',
            font_size=36,
            x=self.game.width / 2, y=self.game.height / 2 + 30,
            anchor_x='center', anchor_y='center',
            batch=batch,
            group=groups[self.render_layer] )
        self.pressAnyKeyLabel = Label(
            'Press any key',
            font_size=18,
            x=self.game.width / 2, y=self.game.height / 2 - 20,
            anchor_x='center', anchor_y='center',
            batch=batch,
            group=groups[self.render_layer] )
        self.blink(None)


    def remove_from_batch(self, batch):
        self.titleLabel.delete()
        self.titleLabel = None
        self.pressAnyKeyLabel.delete()
        self.pressAnyKeyLabel = None
        clock.unschedule(self.blink)


    def blink(self, _):
        blink = self.pressAnyKeyLabel.color == colors[0]
        self.pressAnyKeyLabel.color = colors[blink]
        clock.schedule_once(self.blink, 0.4 + 0.2 * blink)


    def on_key_press(self, _, __):
        clock.schedule_once(lambda _: self.game.start(), 1)
        self.remove_from_game = True
开发者ID:mjs,项目名称:brokenspell,代码行数:47,代码来源:hudtitle.py

示例5: Hud

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
class Hud(object):
    """docstring for Hud"""
    def __init__(self, batch, window):
        super(Hud, self).__init__()
        self.text_ = 'This is the warmup phase'
        self.hp_t = '-1'
        self.armor_t = '-1'
        self.text_active = 5
        self.killmsg_active = False
        self.chat_active = False
        self.batch = batch
        self.scale = vec2(window.width / 1280., window.height / 720.)
        self.hp = Label(self.hp_t, font_name=font, font_size=36,
                        bold=True, x=80, y=10, anchor_x='center',
                        anchor_y='bottom',
                        batch=self.batch)
        self.armor = Label(self.armor_t, font_name=font, font_size=36,
                           x=240, y=10, anchor_x='center', anchor_y='bottom',
                           bold=True,
                           batch=self.batch)
        self.text = Label(self.text_, font_name=font, font_size=36,
                          x=640, y=360, anchor_x='center', anchor_y='center',
                          batch=self.batch)
        self.weapon = Label('melee', font_name=font, font_size=32,
                            x=1160, y=80, anchor_x='center', anchor_y='bottom',
                            color=(0, 255, 255, 255),
                            batch=self.batch)
        self.ammo = Label('1', font_name=font, font_size=36,
                          x=1160, y=10, anchor_x='center', anchor_y='bottom',
                          bold=True,
                          batch=self.batch)
        self.time = Label('0:00', font_name=font, font_size=36,
                          x=640, y=680, anchor_x='center', anchor_y='center',
                          bold=True,
                          batch=self.batch)
        self.chatdoc = FormattedDocument('\n' * 11)
        #self.chatlog = document .FormattedDocument('\n')
        self.chat = ScrollableTextLayout(self.chatdoc, width=500,
                                         height=208, multiline=True,
                                         batch=self.batch)
        self.chat.x = 130
        self.chat.y = 130
        self.chat.content_valign = 'bottom'

        self.killdoc = FormattedDocument('\n')
        self.killmsg = ScrollableTextLayout(self.killdoc, width=300,
                                            height=104, multiline=True,
                                            batch=self.batch)
        self.killmsg.x = 20
        self.killmsg.y = 600

        self.scoredoc = FormattedDocument('0 : 0')
        self.score = ScrollableTextLayout(self.scoredoc, width=150,
                                          height=104, multiline=True,
                                          batch=self.batch)
        self.score.x = 1270
        self.score.y = 650
        self.score.anchor_x = 'right'
        self.score.anchor_y = 'center'

        self.normal_hpcol = (255, 255, 255, 255)
        self.low_hpcol = (255, 128, 0, 255)
        self.high_hpcol = (0, 204, 255, 255)
        self.bname = '_'
        self.aname = '_'
        self.gametime = 70
        self.weaponcolors = {proto.melee: (0, 255, 255, 255),
                             proto.explBlaster: (255, 255, 0, 255)}
        self.killmsg_count = 0
        self.scoreboard = None
        self.weaponbar = WeaponBar(self.batch, self.scale)
        self.do_scale()

    def do_scale(self):
        for item in (self.armor, self.hp, self.text, self.chat, self.killmsg,
                     self.time, self.ammo, self.weapon, self.score):
            item.x *= self.scale.x
            item.y *= self.scale.y

    def init_player(self, players):
        if len(players) == 0:
            self.set_score(0, 0)
        else:
            self.bname = players.values()[0].name
            self.set_score(0, 0)
        self.init_pers_hud()

    def init_pers_hud(self):
        if self.hp._vertex_lists:
            self.weaponbar.batch = self.batch
            self.weapon.batch = self.batch
            self.ammo.batch = self.batch
            self.hp.batch = self.batch
            self.armor.begin_update()
            self.armor.batch = self.batch
            self.armor.end_update()

    def init_spec(self):
        self.weaponbar.remove()
        self.weapon.delete()
#.........这里部分代码省略.........
开发者ID:mokapharr,项目名称:python_game,代码行数:103,代码来源:hud.py

示例6: HudMessage

# 需要导入模块: from pyglet.text import Label [as 别名]
# 或者: from pyglet.text.Label import delete [as 别名]
class HudMessage(GameItem):

    render_layer = 3
    color = (255, 255, 255, 255)

    def __init__(self,
        text,
        font_size=36,
        x=None, y=None,
        anchor_x='center', anchor_y='center',
        font_name=None,
        color=None,
        remove_after=None,
    ):
        GameItem.__init__(self)
        self._text = text
        self.font_size = font_size
        if x is None:
            x = self.game.width / 2
        self.x = x
        if y is None:
            y = self.game.height / 2
        self.y = y
        self.anchor_x = anchor_x
        self.anchor_y = anchor_y
        self.font_name = font_name
        if color is None:
            color = HudMessage.color
        self.color = color
        self.label = None
        # used to detect when Label needs updating
        self.old_source = None
        # message removes itself from game after this many seconds
        self.remove_after = remove_after


    @property
    def text(self):
        return self.source


    @property
    def source(self):
        return self._text


    def add_to_batch(self, batch, groups):
        self.label = Label(
            self.text,
            font_name=self.font_name,
            font_size=self.font_size,
            x=self.x, y=self.y,
            anchor_x=self.anchor_x, anchor_y=self.anchor_y,
            color=self.color,
            batch=batch,
            group=groups[self.render_layer]
        )
        self.old_source = self.source

        def remove(_):
            self.remove_from_game = True

        if self.remove_after:
            clock.schedule_once(remove, self.remove_after)


    def remove_from_batch(self, batch):
        self.label.delete()


    def update(self, _):
        if self.source != self.old_source:
            self.label.text = self.text
            self.old_source = self.source
开发者ID:mjs,项目名称:brokenspell,代码行数:76,代码来源:hudmessage.py


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