本文整理汇总了Python中engine.Engine.load方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.load方法的具体用法?Python Engine.load怎么用?Python Engine.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类engine.Engine
的用法示例。
在下文中一共展示了Engine.load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Engine
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import load [as 别名]
#!/usr/bin/python
from engine import Engine
engine = Engine()
engine.load()
engine.loop()
engine.quit()
quit()
示例2: Editor
# 需要导入模块: from engine import Engine [as 别名]
# 或者: from engine.Engine import load [as 别名]
class Editor(object):
def __init__(self):
self.engine = Engine(width=1280, height=720, gravity=(0, 0), \
linear_damping=10.0, angular_damping=10.0, caption='Editor', \
joint_limit=True, lower_angle=-.2*np.pi, upper_angle=.2*np.pi)
def load(self, filename='model.json'):
self.filename = filename
# load if there's a file
if self.filename and os.path.isfile(self.filename):
self.engine.load(self.filename)
def run(self):
e = self.engine
while not e.exited():
e.window.dispatch_events()
e.window.clear()
if e.window.mouse_pressed:
e.create_mouse_joint()
else:
e.destroy_mouse_joint()
self.handle_keys()
e.update_mouse_joint()
e.step_physics(1)
e.render()
pyglet.clock.tick()
e.window.close()
def handle_keys(self):
e = self.engine
if e.selected:
s = e.selected.userData['size']
s = (s[0]*e.ppm, s[1]*e.ppm)
if e.window.pressed(key.RIGHT):
s = (s[0] + S_STEP, s[1])
if e.window.pressed(key.LEFT):
s = (s[0] - S_STEP, s[1])
if e.window.pressed(key.UP):
s = (s[0], s[1] + S_STEP)
if e.window.pressed(key.DOWN):
s = (s[0], s[1] - S_STEP)
s = (int(max(S_STEP, s[0])), int(max(S_STEP, s[1])))
e.set_box(e.selected, s)
else:
# joint limit
if e.window.pressed(key.UP):
j = e.joint_at(e.window.mouse)
self.change_joint_limit(j, J_STEP)
if e.window.pressed(key.DOWN):
j = e.joint_at(e.window.mouse)
self.change_joint_limit(j, -J_STEP)
if e.window.pressed(key.P):
joint = e.pin_at(e.window.mouse)
if e.window.pressed(key.S):
e.save(self.filename)
if e.window.pressed(key.B):
e.add_dynamic_body(e.window.mouse, (S_STEP * 3, S_STEP * 2))
e.window.reset_keys()
def change_joint_limit(self, j, delta):
if j:
lim = j.upperLimit + delta
lim = max(min(lim, np.pi * 2.0), 0)
j.upperLimit = lim
j.lowerLimit = -lim