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


Python Label.draw方法代码示例

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


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

示例1: IntroLayer

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class IntroLayer(Layer):
    is_event_handler = True
    def __init__(self):
        super(IntroLayer, self).__init__()
        self.img = pyglet.resource.image('background.png')
        self.intro_text = Label('Made by some Asshole:', font_size=24,
                           font_name='Times New Roman',
                           color=(255,255,255,255),
                           anchor_x='left',
                           anchor_y='bottom')
        self.intro_text.position = (0, 0)
        self.add(self.intro_text)
    def draw(self):
        glPushMatrix()
        self.transform()
        self.intro_text.draw()
        self.img.blit(0, 0)
        glPopMatrix()
    def start_game(self):
        scene = Scene()
        scene.add(MultiplexLayer(
                         MainMenu(),
                         OptionsMenu(),
                         HiScoresLayer(),
                         ), z=1)
        scene.add(BackgroundLayer(), z=0)
        director.push(ShuffleTransition(scene, 1.5))
    def on_key_press(self, k, m):
        if k in (pyglet.window.key.ENTER, pyglet.window.key.ESCAPE, pyglet.window.key.SPACE):
            self.start_game()
            return True
    def on_mouse_press(self, x, y, b, m):
        self.start_game()
        return True
开发者ID:mcgillij,项目名称:pygauntlet,代码行数:36,代码来源:gamelayers.py

示例2: GenericControllerBehavior

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class GenericControllerBehavior(CtrlBehavior):
	def __init__(self):
		super(GenericControllerBehavior, self).__init__()
		global behavior_name
		self.display_name = behavior_name
		self.label = Label("", font_size=9, font_name="Cabin Regular", anchor_x="center", anchor_y="top", color=(255, 255, 255, 255))
		self.init_attribute('control_distance', 'ControlDistance', (0,1000), 'generic_controller_default_control_distance', 10)
		
	def associate(self, behavior):
		super(GenericControllerBehavior, self).associate(behavior)
		self.set_control_menu_mode()
	
	def update(self):
		super(GenericControllerBehavior, self).update()
		if self.controlled_attribute:
			distance = self.object.translation.distance(self.association.object.translation)
			distance_ratio = max(0, min(1.3, distance * 1.0 / self.attributes['control_distance'].value) - 0.3)
			value = self.controlled_attribute.range[0] + (distance_ratio * (self.controlled_attribute.range[1] - self.controlled_attribute.range[0]))
			self.controlled_attribute.set(value)
	
	def draw_foreground(self):
		super(GenericControllerBehavior, self).draw_foreground()
		if self.controlled_attribute:
			coords = self.object.screen_coords()
			self.label.position = coords.x, coords.y - 10
			self.label.element.text = "%s: %s" % (self.controlled_attribute.display_name, self.controlled_attribute.to_string())
			self.label.element.color = (255, 255, 255, int(self.object.alpha() * 255))
			self.label.draw()
开发者ID:ice3,项目名称:Glovebox,代码行数:30,代码来源:generic_controller.py

示例3: Interface

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class Interface(Layer):
	def __init__(self, model):
		self.model = model
		self.portraits = {'wizard': Hero_portriat_DM(), 'priest': Hero_portriat_DM(),
						 'warrior': Hero_portriat_DM(),'rogue': Hero_portriat_DM()}
		for c in self.portraits:
			self.portraits[c].reload(model, c)
		self.money = starting_money
		
	def draw(self):
		w, h = director.get_window_size()
		sc = 1920/w
		self.label = Label('%d' %self.money, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255))
		self.label.position = (1670//sc, 1030//sc)
		self.label.draw()
		for c in self.portraits:
			self.portraits[c].draw()
开发者ID:XRater,项目名称:Dungeon-defenders,代码行数:19,代码来源:gamemodel.py

示例4: FileInfoLayer

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class FileInfoLayer(Layer):

	is_event_handler = False

	def __init__(self, text='', position=(0, 0), **kwargs):
		print("INIT >>> FileInfoLayer.init() ")
		super(FileInfoLayer, self).__init__()
		self.model = None
		self.background = cocos.layer.util_layers.ColorLayer(0, 0, 0, 128, 1000, 30)
		self.label = Label(
			"Label1", x=10, y=10,
			font_name='Gill Sans',
			font_size=10,
		    color=(250, 250, 250, 255),
		    anchor_x = "left",
		    anchor_y = "baseline",
		    multiline = False
		)

		self.add(self.background, name="background")
		self.add(self.label, name="label")


	def on_slideshow_model_update(self, model):
		print("FileInfoLayer.ON_SLIDESOW_MODEL_UPDATE")
		self.model = model
		self.label.element.text = self.text
		print("FileInfoLayer: %s" % self.text)

	def on_draw(self):
		self.background.draw()
		self.label.draw()

	@property
	def text(self):
		if self.model is None:
			return ''
		else:
			return '%d / %d: %s' % \
		        (self.model.current_id+1, self.model.total_files,
		        self.model.current_file)
开发者ID:seeminglee,项目名称:ImageViewer64,代码行数:43,代码来源:iv64_cocos.py

示例5: Skill

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class Skill():
	def __init__(self, name, number, hero, model):
		w, h = director.get_window_size()
		sc = 1920/w
		self.name = name
		self.number = number
		self.sprite = Sprite(Images.skill_image[self.name], ((1208)//sc, (899 - skill_pos[self.number])//sc), scale = 1/sc)
		self.skill = Skills[self.name](hero , model)
	
	def draw(self):
		w, h = director.get_window_size()
		sc = 1920/w
		if (self.skill.learnt):
			self.sprite.draw()
			if self.skill.cd_left:
				self.label = Label('%d' %self.skill.cd_left, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
				self.label.position = ((1208)//sc, (899 - skill_pos[self.number])//sc)
				self.label.draw()
	
	def use(self):
		if self.skill.available:
			self.skill.use()
开发者ID:XRater,项目名称:Dungeon-defenders,代码行数:24,代码来源:gamemodel.py

示例6: Hero_portriat_DM

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class Hero_portriat_DM():
	def reload(self, model, hero_name):
		w, h = director.get_window_size()
		sc = 1920/w
		self.model = model
		self.name = hero_name
		if self.name == 'wizard':
			self.hero = self.model.heroes[self.name]
			self.sprite = Sprite(Images.hero_icons[self.name], (1600//sc, 900//sc), scale = 1/sc)
			self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1600//sc, 900//sc), scale = 1/sc)
			self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
			self.label.position = 1600//sc, 870//sc
		if self.name == 'priest':
			self.hero = self.model.heroes[self.name]
			self.sprite = Sprite(Images.hero_icons[self.name], (1720//sc, 900//sc), scale = 1/sc)
			self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1720//sc, 900//sc), scale = 1/sc)
			self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
			self.label.position = 1720//sc, 870//sc
		if self.name == 'warrior':
			self.hero = self.model.heroes[self.name]
			self.sprite = Sprite(Images.hero_icons[self.name], (1600//sc, 780//sc), scale = 1/sc)
			self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1600//sc, 780//sc), scale = 1/sc)
			self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
			self.label.position = 1600//sc, 750//sc
		if self.name == 'rogue':
			self.hero = self.model.heroes[self.name]
			self.sprite = Sprite(Images.hero_icons[self.name], (1720//sc, 780//sc), scale = 1/sc)
			self.sprite_black = Sprite(Images.hero_icons_black[self.name], (1720//sc, 780//sc), scale = 1/sc)
			self.label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=20//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
			self.label.position = 1720//sc, 750//sc
	def draw(self):
		if self.hero.alive:
			self.sprite.draw()
			self.label.font_name = '%d' %self.hero.stats.health
			self.label.draw()
		else:
			self.sprite_black.draw()
开发者ID:XRater,项目名称:Dungeon-defenders,代码行数:39,代码来源:gamemodel.py

示例7: HeroStats

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class HeroStats(Label):
	def __init__(self, hero):
		w, h = director.get_window_size()
		sc = 1920/w
		self.hero = hero
		self.health_label = Label('%d' %self.hero.stats.health, font_name='Times New Roman', font_size=28//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
		self.health_label.position = 1300//sc, 315//sc
		self.exp_label = Label('%d' %self.hero.stats.exp, font_name='Times New Roman', font_size=28//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
		self.exp_label.position = 1300//sc, 155//sc
		self.luck_label = Label('%d%%' %self.hero.stats.luck, font_name='Times New Roman', font_size=28//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
		self.luck_label.position = 1300//sc, 245//sc
		self.lvl_label = Label('%d' %self.hero.stats.lvl, font_name='Times New Roman', font_size=18//sc, anchor_x='center', anchor_y='center', color = (0, 0, 0, 255) )
		self.lvl_label.position = 1618//sc, 112//sc
		self.attack_label = Label('%d' %self.hero.stats.attack, font_name='Times New Roman', font_size=28//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255) )
		self.attack_label.position = 1550//sc, 315//sc
		self.armor_label = Label('%d' %self.hero.stats.armor, font_name='Times New Roman', font_size=28//sc, anchor_x='center', anchor_y='center', color = (255, 0, 0, 255))
		self.armor_label.position = 1550//sc, 245//sc

	def draw(self):
		self.health_label.draw()
		self.lvl_label.draw()
		self.exp_label.draw()
		self.luck_label.draw()
		self.attack_label.draw()
		self.armor_label.draw()
开发者ID:XRater,项目名称:Dungeon-defenders,代码行数:27,代码来源:gamemodel.py

示例8: Behavior

# 需要导入模块: from cocos.text import Label [as 别名]
# 或者: from cocos.text.Label import draw [as 别名]
class Behavior(object):
	"""A behavior defines the virtual part of a tracked object.
	
	A behavior can interact with its environment through 5 entry points that can be overridden :
	update_tracking -- New data arrives from the tracking subsystem.
	update -- Update the internal state.
	draw_background -- Draw the background part in 2D.
	draw_3d -- Draw the 3D part.
	draw_foreground -- Draw the foreground part in 2D."""
	def __init__(self):
		"""Initialize an empty behavior."""
		super(Behavior, self).__init__
		self.display_name = None
		self.display_name_cached = None
		self.display_name_label = Label("", font_size=8, font_name="Cabin Bold", anchor_x="center", anchor_y="bottom", color=(255, 255, 255, 255))
		self.object = None
		self.observers = collections.defaultdict(list)
		self.attributes = collections.defaultdict(BehaviorAttribute)
		self.association = None
		self.association_selection = None
		self.association_selection_shaker = ShakeRecognizer.ShakeRecognizer()
		self.association_name = "Associate"
		self.association_mode = False
	
	def init_attribute(self, name, display_name, range, option_name, default_value, formatter = None):
		self.attributes[name].display_name = display_name
		self.attributes[name].range = range
		if formatter:
			self.attributes[name].formatter = formatter
		self.attributes[name].set(director.app.options.setdefault(option_name, default_value))
	
	def max_association_selection_time(self):
		return director.app.options.setdefault('max_association_selection_time', 2)
	
	def register_for(self, notification, observer):
		"""Register for a notification type as an observer."""
		if not observer in self.observers[notification]:
			self.observers[notification].append(observer)

	def unregister_from(self, notification, observer):
		"""Stop observing a notification type."""
		try:
			self.observers[notification].remove(observer)
		except ValueError:
			pass
	
	def notify_for(self, notification, *args):
		"""Notify observers for something."""
		for observer in self.observers[notification]:
			observer.notification_arrived_for(notification, self, *args)
	
	def notification_arrived_for(self, notification, sender, *args):
		"""Handle new notifications."""
		if notification == "detached":
			self.behavior_detached(sender, *args)
	
	def behavior_detached(self, sender, *args):
		"""Handle a 'detached' notification."""
		if self.association == sender:
			self.unassociate()
	
	def will_detach(self, object):
		self.object = None
		self.notify_for("detached")
		self.has_just_detached()
		
	def did_attach(self, object):
		self.object = object
		self.has_just_attached(object)
	
	def associate(self, behavior):
		"""Start an unilateral association from this behavior to a specified behavior."""
		if self.association:
			unassociate()
		self.association = behavior
		behavior.register_for("detached", self)
		return True
	
	def unassociate(self):
		"""Stop being associated with the current associated behavior, if any."""
		if not self.association:
			return
		self.association.unregister_from("detached", self)
		self.association = None
		
	def has_just_attached(self, object):
		"""Do something when the behavior will cease to be attached to a tracked object."""
		pass
	
	def has_just_detached(self):
		"""Do something when the behavior will attach to a tracked object."""
		pass
	
	def has_object(self):
		"""Tell if the behavior is attached to a tracked object."""
		return self.object != None
		
	def draw_association(self):
		"""Draw a line between the associated behavior's object and this behavior's object."""
		if not self.association:
#.........这里部分代码省略.........
开发者ID:ice3,项目名称:Glovebox,代码行数:103,代码来源:Behavior.py


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