【发布时间】:2013-06-30 10:05:59
【问题描述】:
我正在尝试为 event based editor 创建一个算法,例如在星际争霸 2 编辑器中可以支持:
- 创建用户界面
- 播放声音
- 处理键盘/鼠标输入
- 显示消息
- 按钮(或一些引用的 UI 对象)被按下等。
与星际争霸 2 编辑器中的内容几乎相同(当然也不是 3D 内容)
到目前为止,我正在考虑使用 JSON ,将每个事件添加到对象中,然后循环遍历它们并使用 addEventListener() 方法创建事件。
JSON 事件对象(当然它会由用户在编辑器中创建,无需编程):
var Events={
//your event's names here
onReady:{ //on page ready to manipulate
displayMessage:{//just a simple popup
text:"Hello user!",
title:"Welcome!",
type:"normal",
},
createButton:{ //creates a buton on the screen
text:"Click me!",
id:"myButton"
}
},
onClick:{
id:"myButton" ,//the id of the button we just created
actions:{ //the actions applied after we click the button
displayMessage:{//just a simple popup
text:"You pressed me!",
title:"Button",
type:"error",//show the message as an error
}
}
}
}
我发现了一些软件 (GameMaker,Construct 2,GameDevelop),如果你想了解一下我说的是(如果你还不知道星际争霸 2 编辑器)
我的问题是: 我可以使用什么算法来实现这一点?
【问题讨论】:
-
这样做的问题是你不能将多个回调绑定到 1 个事件,它还会导致大量配置和无休止的缩进级别。
标签: javascript jquery json events editor