我正在 Starling 中创建一个游戏,并希望使用 XML 来保留游戏中出现的所有消息对话。以下是如何使用它的示例:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<items>
<bottle>
<interact>
<examine>
<state id="1">
<message id="1">This is the first time I have seen this bottle</message>
<message id="2">This is the first time I have seen this bottle 2</message>
<message id="3">This is the first time I have seen this bottle 3</message>
<message id="4">This is the first time I have seen this bottle 4</message>
</state>
<state id="2">
<message id="1">This is the second time I have seen this bottle</message>
<message id="2">This is the second time I have seen this bottle 2</message>
<message id="3">This is the second time I have seen this bottle 3</message>
<message id="4">This is the second time I have seen this bottle 4</message>
</state>
<state id="3">
<message id="1">This is the third time I have seen this bottle</message>
<message id="2">This is the third time I have seen this bottle 2</message>
<message id="3">This is the third time I have seen this bottle 3</message>
<message id="4">This is the third time I have seen this bottle 4</message>
</state>
</examine>
<chat>
<state>
<message id="1">I cannot talk to a bottle</message>
<message id="2">I cannot talk to a bottle 2</message>
<message id="3">I cannot talk to a bottle 3</message>
<message id="4">I cannot talk to a bottle 4</message>
</state>
</chat>
<action>
<state>
<message id="1">I picked up the bottle</message>
<message id="2">I picked up the bottle 2</message>
<message id="3">I picked up the bottle 3</message>
<message id="4">I picked up the bottle 4</message>
</state>
</action>
</interact>
</bottle>
<item2>
<interact>
<examine>
<state id="1">
<message id="1">This is the first time I have seen item 1</message>
<message id="2">This is the first time I have seen item 2</message>
<message id="3">This is the first time I have seen item 3</message>
</state>
<state id="2">
<message id="1">This is the second time I have seen item 1</message>
<message id="2">This is the second time I have seen item 2</message>
<message id="3">This is the second time I have seen item 3</message>
</state>
<state id="3">
<message id="1">This is the third time I have seen item 1</message>
<message id="2">This is the third time I have seen item 2</message>
<message id="3">This is the third time I have seen item 3</message>
</state>
</examine>
<chat>
<state>
<message id="1">I cannot talk to a item</message>
<message id="2">I cannot talk to a item 2</message>
<message id="3">I cannot talk to a item 3</message>
<message id="4">I cannot talk to a item 4</message>
</state>
</chat>
<action>
<state>
<message id="1">I picked up the item</message>
<message id="2">This may be useful</message>
<message id="3">I will use this for something</message>
<message id="4">I have put it in my pocket</message>
</state>
</action>
</interact>
</item2>
</items>
<characters></characters>
<backgrounds></backgrounds>
</data>
如您所见,有一个与项目交互的 3 种类型的结构。检查、谈话和行动(例如接送)。state id 决定了游戏的状态(游戏中取得了多少进展),这很重要,因为消息可能会根据发生的情况而改变。当事件发生时,这会更新游戏中的所有内容。例如
状态 1:
“在我与罗杰交谈之前,我无法取走这件物品!”
与 Roger 交谈并进入状态 2:
状态 2:
“我捡起那件东西是因为我和罗杰谈过了!”
我创建了一个名为 message box 的类,它根据 state 和 currentTarget (item) 获取 XMLList
什么是只获取我想要的节点的好方法:
我想得到:
<message id="1">I picked up the item</message>
<message id="2">This may be useful</message>
<message id="3">I will use this for something</message>
<message id="4">I have put it in my pocket</message>
我不想写出一个巨大的 if 语句来返回我想要的节点:
//get a list
if (item2 && state == 1) {
var message:XMLList = messageXML.items.item2.interaction.action.state.text();
}
else if(item2 && state = 2) {
var message:XMLList = messageXML.items.item2.interaction.action.state.text();
}
etc....
大问题,任何帮助将不胜感激。
更新:
我希望它返回一个 XMLList,其中的字符串以这样的方法传递:
private function searchForMessages(message:XML, target:String, state):XMLList
{
}