Exemplo n.º 1
0
  def loadFromXML(self, XMLRoot):
    self.name = XMLRoot.find("name").text
    self.animation = ResourceManager.getAnimation(self.name).produce()
    self.layer = int(XMLRoot.find("layer").text)
    self.dp = Vector2(float(0), float(0))
    if XMLRoot.find("dx") != None and XMLRoot.find("dy") != None:
      self.dp = Vector2(float(XMLRoot.find("dx").text),
                      float(XMLRoot.find("dy").text))
    self.origin = XMLRoot.find("origin")
    if self.origin != None:
      self.origin = Util.parseVector2(self.origin)
    if XMLRoot.find("width") != None and XMLRoot.find("height") != None:
      self.size = Vector2(float(XMLRoot.find("width").text),
                          float(XMLRoot.find("height").text))
    else:
      self.size = Vector2(-1, -1)
    
    if XMLRoot.find("tileWidth") == None or XMLRoot.find("tileHeight") == None:
      self.tileSize = None
    else:
      self.tileSize = Vector2(float(XMLRoot.find("tileWidth").text),
                              float(XMLRoot.find("tileHeight").text))
    
    self._sprite = Sprite(self.animation._anim.getTexture(), self.animation.getRect())
    if type(self.origin) == Vector2:
      self._sprite.origin = self.origin

    # Default value for when there is no FacingComponent
    self._facingLeft = False
    
    # This needs to be the ordering. Facing interferes with entitySizeUpdate.
    self.reset()
    self.entitySizeUpdate()