本文整理汇总了Python中sprite.Sprite.gravity_on方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.gravity_on方法的具体用法?Python Sprite.gravity_on怎么用?Python Sprite.gravity_on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.gravity_on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameView
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import gravity_on [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