Game Development Reference
In-Depth Information
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlActor = xmlDoc.CreateElement(
Actor
);
xmlDoc.AppendChild(xmlActor);
XmlAttribute xmlActorId = xmlDoc.CreateAttribute(
id
);
xmlActorId.InnerText = m_SelectedActorId.ToString();
xmlActor.Attributes.Append(xmlActorId);
XmlNode elementNode = FindActorElementFromXPath(xPath);
XmlNode componentNode = elementNode.ParentNode;
string componentName = componentNode.Name;
string elementName = elementNode.Name;
XmlElement xmlComponent = xmlDoc.CreateElement(componentName);
xmlActor.AppendChild(xmlComponent);
XmlElement xmlElementName = xmlDoc.CreateElement(elementName);
xmlComponent.AppendChild(xmlElementName);
xmlElementName.InnerText = newValue;
NativeMethods.ModifyActor(xmlDoc.InnerXml);
}
private XmlNode FindActorElementFromXPath(string xpath)
{
XmlNodeList nodeList = m_ActorXml.SelectNodes(xpath);
return nodeList[0];
}
This code grabs the text box control and creates a snippet of XML. Assume for the
sake of argument that the component being modified is the < Texture> element of
the GridRenderComponent . Also assume that the actor ID is 1, and the new tex-
ture name is art\sky.jpg. Here is the XML that would be created:
<Actor id=
>
<GridRenderComponent>
<Texture>art\sky.jpg</Texture>
</GridRenderComponent>
</Actor>
1
Once the XML is created, it is sent into NativeMethods.ModifyActor() . If you
recall from the earlier section
this will cause the
GridRenderComponent of the actor to be reinitialized, but since the only part of
the XML that is defined is the texture name, only that element will be modified. All
the other values currently in the actor remain the same.
Actor Modification Functions,
 
Search WWH ::




Custom Search