本文整理汇总了Python中sprites.Sprite.set_margins方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.set_margins方法的具体用法?Python Sprite.set_margins怎么用?Python Sprite.set_margins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprites.Sprite
的用法示例。
在下文中一共展示了Sprite.set_margins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import set_margins [as 别名]
class Game():
def __init__(self, canvas, parent=None, path=None):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height()
self._scale = self._width / 1200.
self._target = 0
self._tries = 0
self.level = 0
self._picture_cards = []
self._small_picture_cards = []
self.food_cards = []
self._group_cards = []
self._quantity_cards = []
self._balance_cards = []
self._last_twenty = []
self._background = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._background = Sprite(
self._sprites, 0, 0, GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images','background.png'),
self._width, self._height))
self._background.set_layer(0)
self._background.type = None
self._background.hide()
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'word-box.png'),
int(350 * self._scale), int(100 * self._scale))
for i in range(len(FOOD_DATA) / 4):
FOOD.append([FOOD_DATA[i * 4 + NAME], FOOD_DATA[i * 4 + CALS],
FOOD_DATA[i * 4 + GROUP], FOOD_DATA[i * 4 + IMAGE]])
self.food_cards.append(None)
self._picture_cards.append(None)
for j in range(6):
self._small_picture_cards.append(None)
self.allocate_food(0)
x = 10
dx, dy = self.food_cards[0].get_dimensions()
y = 10
for i in range(len(MYPLATE)):
self.word_card_append(self._group_cards, self.pixbuf)
self._group_cards[-1].type = i
self._group_cards[-1].set_label(MYPLATE[i][0])
self._group_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(QUANTITIES)):
self.word_card_append(self._quantity_cards, self.pixbuf)
self._quantity_cards[-1].type = i
self._quantity_cards[-1].set_label(QUANTITIES[i])
self._quantity_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(BALANCE)):
self.word_card_append(self._balance_cards, self.pixbuf)
self._balance_cards[-1].type = i
self._balance_cards[-1].set_label(BALANCE[i])
self._balance_cards[-1].move((x, y))
y += int(dy * 1.25)
self._smile = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'correct.png'),
int(self._width / 2),
int(self._height / 2)))
self._smile.set_label_attributes(36)
self._smile.set_margins(10, 0, 10, 0)
self._frown = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'wrong.png'),
int(self._width / 2),
int(self._height / 2)))
self._frown.set_label_attributes(36)
self._frown.set_margins(10, 0, 10, 0)
self.build_food_groups()
#.........这里部分代码省略.........