简体   繁体   English

在Silverlight中动态加载设置

[英]Dynamically Loading Settings In Silverlight

I have a simple game I'm working on, written in Silverlight. 我有一个正在使用Silverlight编写的简单游戏。 What I'm trying to do is allow changes to the games appearance (the images used, the sounds played, and the location of objects in the game) without modifying or recompiling any of the Silverlight code. 我想做的是允许更改游戏外观(所使用的图像,播放的声音以及游戏中对象的位置),而无需修改或重新编译任何Silverlight代码。

The approach I'm trying to take is passing in an 'ID' to the Silverlight object. 我尝试采用的方法是将“ ID”传递给Silverlight对象。 That ID gets injected into the URLs for all of the resources. 该ID将注入所有资源的URL中。

http://myServer.com/MyGame/1/Images/1.png http://myServer.com/MyGame/1/Images/1.png

If I make another HTML page and pass in a GameID of 2 I get an entirely different set of images and sounds. 如果制作另一个HTML页面并传递2的GameID,我将获得完全不同的图像和声音集。 That part appears to be working correctly (even if it is misguided). 该零件似乎工作正常(即使被误导了)。

But I also have some configuration items like the position of certain things on the screen and some rules that affect gameplay. 但是我也有一些配置项目,例如某些东西在屏幕上的位置以及一些影响游戏玩法的规则。 I wanted to throw this into a XML file and have the game load the file using the same approach for Images and Sounds - but I can't seem to get it to work. 我想将其放入XML文件中,然后让游戏使用与“图像和声音”相同的方法加载文件-但我似乎无法使其正常工作。 I haven't found any way to download a file synchronously. 我还没有找到同步下载文件的任何方法。

I had some ideas - making my own 'Loading screen' downloading the file asynchronously, reading the file/setting up the game, letting the game start. 我有一些想法-制作自己的“加载屏幕”以异步方式下载文件,读取文件/设置游戏并开始游戏。 But it I get the feeling I might be reinventing the wheel or doing something that's just silly. 但是我感觉到自己可能正在重新发明轮子或做一些愚蠢的事情。

Is there a better way to accomplish this? 有没有更好的方法可以做到这一点?

To some degree yes you would be re-inventing the wheel but the wheel you're re-inventing is not a particularly complex one. 在某种程度上,您会重新发明轮子,但是您要重新发明的轮子并不是特别复杂。 If you were creating a line of business app you would probably use the BusyIndicator control for the Silverlight toolkit. 如果要创建业务应用程序,则可能会在Silverlight工具箱中使用BusyIndicator控件。 This control allows some "Loading..." UI to be presented while significant background activity runs. 此控件允许在运行大量后台活动时显示一些“正在加载...” UI。

You could use this as a starting point, however you would probably want to replace its default style and specifically the default template in the style to present UI in keeping with your game's graphics. 您可以以此为起点,但是您可能希望替换其默认样式,特别是替换样式中的默认模板,以呈现与游戏图形保持一致的UI。

However including the toolkit just for this function may not be a good trade-off. 但是,仅包含用于此功能的工具包可能不是一个好的折衷方案。 Having created your own template it would be very easy to then re-create the very simple control that sits behind the template. 创建了自己的模板后,很容易重新创建位于模板后面的非常简单的控件。 So yes you would have re-created the wheel but most of the effort would be in the graphics unique to your game anyway and the rest might be a worthwhile trade off for not having to include a toolkit dll in your project. 因此,是的,您将重新创建轮子,但是无论如何,大部分工作将集中在游戏特有的图形中,而其余的部分可能是值得的,因为不必在项目中包含工具包dll。

只要用户知道“事情”正在进展/继续他们会很高兴的,我认为加载屏幕是完全可以接受的,尤其是在游戏社区,几乎每个游戏都要求您等待地图等加载时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM