本文整理汇总了Python中gui.Gui.on_touch_down方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.on_touch_down方法的具体用法?Python Gui.on_touch_down怎么用?Python Gui.on_touch_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gui.Gui
的用法示例。
在下文中一共展示了Gui.on_touch_down方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import on_touch_down [as 别名]
#.........这里部分代码省略.........
self.background.addLayer(layer)
def setupShip(self,filename):
domLevel = parse(filename)
shipNodes = domLevel.getElementsByTagName("ship")
shipNode = shipNodes[0]
self.mainbody = Body()
for node in shipNode.childNodes:
if node.localName == "position":
position = node.getAttribute('value')
values = position.split(',')
self.mainbody.setPosition(float(values[0]),float(values[1]))
if node.localName == "mobile":
m = Mobile()
for childnode in node.childNodes:
if childnode.localName == "position":
values = childnode.getAttribute('value').split(',')
m.setPosition(float(values[0]),float(values[1]))
if childnode.localName == "velocity":
values = childnode.getAttribute('value').split(',')
m.setVelocity(float(values[0]),float(values[1]))
if childnode.localName == "thrust":
values = childnode.getAttribute('value').split(',')
m.setThrustVector(float(values[0]),float(values[1]))
m.setInitialThrustVector(float(values[0]),float(values[1]))
if childnode.localName == "mass":
value = childnode.getAttribute('value')
m.setMass(float(value))
if childnode.localName == "radius":
value = childnode.getAttribute('value')
m.setRadius(float(value))
if childnode.localName == "texture":
value = childnode.getAttribute('value')
m.setTexture(TextureHelper.loadTextureFromFile(value))
#if childnode.localName == "physicalPoints":
# for ppointnode in childnode.childNodes:
# if ppointnode.localName == "point":
# values = ppointnode.getAttribute('value').split(',')
# m.addPhysicalPoint(Vector2d(float(values[0]),float(values[1])))
m.setupPhysicalPoint()
self.mainbody.addMobile(m)
self.mainbody.init()
focus_position = self.mainbody.getPosition()
self.world.addMobile(self.mainbody)
def setupWorld(self,filename):
self.world.reset()
domLevel = parse(filename)
worldNodes = domLevel.getElementsByTagName("world")
for node in worldNodes[0].childNodes:
if node.localName == "gravity":
values = node.getAttribute('value').split(',')
self.world.setGravity(float(values[0]),float(values[1]))
if node.localName == "landingzone":
values = node.getAttribute('value').split(',')
self.world.setLandingzone(Landingzone(float(values[0]),float(values[1]),float(values[2]),float(values[3]),TextureHelper.loadTextureFromFile('checker.png')))
h = Config.getint('graphics', 'height')
w = Config.getint('graphics', 'width')
p0 = Plane(1,0,-10)
p1 = Plane(0,-1,h-10)
p2 = Plane(-1,0,w-10)
p3 = Plane(0,1,-64)
self.world.addPlane(p0)
self.world.addPlane(p1)
self.world.addPlane(p2)
self.world.addPlane(p3)
#self.world.setGravity(0.0,-1.8)
def setupGame(self):
self.setupMenu()
def updateGame(self,canvas):
if self.mainbody != 0:
self.camera.follow(self.mainbody)
self.camera.setup(canvas)
self.background.draw(canvas)
self.world.draw(canvas)
self.gui.draw(canvas)
self.world.step(1/60.)
if self.gameIsRunning():
res = self.checkVictoryCondition()
if res != 0:
if res == -1:
self.gui.messaging.displayText('FAIL ! !',200)
self.gameResult = -1
Clock.schedule_once(self.setupLevel, 5)
if res == 1:
self.gui.messaging.displayText('SUCCESS ! !',200)
self.gameResult = 1
self.currentLevel += 1
Clock.schedule_once(self.setupLevel, 5)
def on_touch_down(self, touch):
worldpos = self.camera.screenToWorld(touch.pos[0],touch.pos[1])
self.world.on_touch_down(worldpos)
self.gui.on_touch_down(touch)