本文整理汇总了Python中sprite.Sprite.play方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.play方法的具体用法?Python Sprite.play怎么用?Python Sprite.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.play方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameView
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import play [as 别名]
class GameView(Screen):
tile_atlas = Atlas("imgs/tiles/tile.atlas")
background_image = ObjectProperty(
Image(source='imgs/forest8bit.jpg')
)
def __init__(self, **kwargs):
super(GameView, self).__init__(**kwargs)
self.ryu_atlas = Atlas("imgs/mage.atlas")
self.ryu_sheet = {"run": ["0", "1", "2"]}
self.sprite = Sprite(self.ryu_sheet, self.ryu_atlas)
self.sprite.y = 500
self.sprite.x = 100
self.sprite.sprite_fps = 8
self.add_widget(self.sprite)
self.rigth = True
self.back = False
self.sprite.size_hint = [1.0 / x * 20 for x in self.sprite.size]
print self.sprite.size, self.sprite.size_hint
# must be int, not delta time
self.fps = 0
# self.sprite.flip = True
def update(self, dt):
self.fps += 1
self.sprite.play("run", self.fps)
self.sprite.gravity_on()
self.walk_way()
if self.fps > 30:
self.fps = 0
def walk_way(self):
print self.sprite.x, self.width
if self.sprite.x < self.width - self.sprite.width and self.rigth:
self.sprite.x += 6
else:
if not self.back:
self.back = True
self.sprite.flip_h()
self.rigth = False
if self.sprite.x > self.width - self.width and not self.rigth:
self.sprite.x += -6
else:
if self.back:
self.back = False
self.sprite.flip_h()
self.rigth = True
def jump(self):
if self.sprite.jumps < 2:
self.sprite.jumps += 1
self.sprite.speed = -self.sprite.jump_force
示例2: Player
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import play [as 别名]
class Player (Sprite):
def __init__ (self, x, y):
Sprite.__init__(self, x, y, 'princess')
self.grid_x = x
self.grid_y = y
self.light = Sprite(x, y, 'light')
self.light.offset_x = -96
self.light.offset_y = -106
self.light.play('default', loop=True)
# walk timer
self.timer = None
# default orientation
self.ori = 'up'
# animations
self.add_anim('walk_up', common.WALK_MOVEMENT_TIME, range(0, 9))
self.add_anim('walk_left', common.WALK_MOVEMENT_TIME, range(9, 18))
self.add_anim('walk_down', common.WALK_MOVEMENT_TIME, range(18, 27))
self.add_anim('walk_right', common.WALK_MOVEMENT_TIME, range(27, 36))
@property
def grid_x (self):
return int(self.x / common.TILE_SIZE)
@property
def grid_y (self):
return int(self.y / common.TILE_SIZE)
@grid_x.setter
def grid_x (self, x):
self.x = x * common.TILE_SIZE
@grid_y.setter
def grid_y (self, y):
self.y = y * common.TILE_SIZE
def walk (self, x, y):
assert(x == 1 or x == -1 or x == 0)
assert(y == 1 or y == -1 or y == 0)
if x == 0 and y == 0:
return
elif self.timer is None or self.timer.is_complete():
x *= common.TILE_SIZE
y *= common.TILE_SIZE
self._prev_x = self.x
self._prev_y = self.y
self._next_x = self.x + x
self._next_y = self.y + y
self._move_x = x
self._move_y = y
if x < 0:
self.ori = 'left'
elif x > 0:
self.ori = 'right'
elif y > 0:
self.ori = 'down'
else:
self.ori = 'up'
self.play('walk_' + self.ori)
self.timer = Timer(common.WALK_MOVEMENT_TIME)
def update (self, time):
Sprite.update(self, time)
self.light.update(time)
if self.timer is not None and not self.timer.is_complete():
self.timer.update(time)
self.x = self._prev_x + self.timer.percent_done * self._move_x
self.y = self._prev_y + self.timer.percent_done * self._move_y
# adjust player light position
self.light.x = self.x
self.light.y = self.y