我一直在使用我製作了一年的初級引擎創建文本冒險。存儲文本冒險故事數據AS3
對於這個故事,我有一個對象數組(是,它叫什麼?)用各種故事數據的東西,我通過
解析有人告訴我,使用它我的方式是愚蠢的,因爲它是應該用於其他的東西,但我只使用它,因爲它很容易學會如何解析數據,因爲我是一個初學者
它是越來越乏味的寫故事和做每個部分的東西(創造的背景和這樣的)因爲它太長了。
有沒有什麼方法可以讓我更容易寫故事?
這裏的對象陣列設置(與選擇)單個零件
public static var parts:Object =
{
"0":
{
"text":"Text here",
"choices":
{
"response1":
{
"text":"Response1",
"nextPart":"1"
},
"response2":
{
"text":"Response2",
"nextPart":"2"
}
},
"background": Assets.AssetClass.Background1,
"BGM":"bg1"
},
}
這裏是改變它們與部分如何我的引擎處理的例子,:
我有一個輸入檢查器檢查當輸入被按下,然後做什麼取決於屏幕上的東西
public function onEnter(button:KeyboardEvent):void
{
if (button.keyCode == 32 && !Won)
{
if (Dead && textFinished && !choosing) // pressing enter while dead and the text is still writing
{
curPart = parts[curPart]["lastPart"] // lastPart will only be stored in parts that have the player die
textFinished = false
Dead = false;
myTextField.text = ""
counter = 0;
sInt = setInterval(addCharackter, textSpeed)
if (stage.getChildByName("cText"))
{
stage.removeChild(continueText)
}
if (parts[curPart].hasOwnProperty("background")) //check if the background needs to change.
{
if (stage.getChildByName("img"))
{
stage.removeChild(background)
}
background = new Background(parts[curPart], 800, 600)
stage.addChildAt(background, 0)
}
}
if (!textFinished && !choosing)// pressing enter when there's no choices on the screen and the text isn't finished and the text is still writing
{
this.myTextField.text = this.parts[this.curPart]["text"];
clearInterval(this.sInt);
this.textFinished = true;
if (parts[curPart].hasOwnProperty("choices"))
{
choosing = true
createOptions(); // function for parsing through the responses bit of that part and displaying them
}
else
{
stage.addChildAt(continueText, 2)
}
if (parts[curPart].hasOwnProperty("lastPart"))
{
Dead = true;
dead()
}
}
else if (textFinished && !choosing && !Dead) // pressing enter if there's no choices on the screen and there's no choices (it'll take you to the next part)
{
trace("Text finished!!")
curPart = parts[curPart]["nextPart"]
myTextField.text = ""
counter = 0;
sInt = setInterval(addCharackter, textSpeed)
textFinished = false;
if (parts[curPart].hasOwnProperty("background"))
{
if (stage.getChildByName("img"))
{
trace("Removed!")
stage.removeChild(background)
}
background = new Background(parts[curPart], 800, 600)
stage.addChildAt(background, 0)
}
if (parts[curPart].hasOwnProperty("BGM")) // does the current part have a new background music?
{
trace("Music!!!!")
sndBGMusic = musicArray[parts[curPart]["BGM"]]
sndBGMusicChannel.stop()
sndBGMusicChannel = sndBGMusic.play(0, 9999999999)
stage.addChildAt(background, 0)
}
stage.removeChild(continueText)
}
}
}
你可以提供一些關於你的代碼如何工作的上下文嗎?具體來說,我想知道如何在腳本的其他部分使用這個零件對象。 'parts'在您的引擎中實際上做了什麼?它看起來像使用玩家輸入來返回一些結果。我們能否看到一個如何使用這個「零件」對象的例子? –
零件包含遊戲的所有場景。我通過解析每個部分並獲取相關數據(例如:文本,檢查是否有選擇)並根據該數據在屏幕上顯示內容。 – Ducktor
你能通過編輯你的帖子在你的問題中展示一個例子嗎? –