我有这样的结构:
public struct MapTile
{
public int bgAnimation;
public int bgFrame;
}
Run Code Online (Sandbox Code Playgroud)
但当我用foreach循环它以改变动画帧我不能这样做...
这是代码:
foreach (KeyValuePair<string, MapTile> tile in tilesData)
{
if (tilesData[tile.Key].bgFrame >= tilesData[tile.Key].bgAnimation)
{
tilesData[tile.Key].bgFrame = 0;
}
else
{
tilesData[tile.Key].bgFrame++;
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我编译恐怖:
Error 1 Cannot modify the return value of 'System.Collections.Generic.Dictionary<string,Warudo.MapTile>.this[string]' because it is not a variable
Error 2 Cannot modify the return value of 'System.Collections.Generic.Dictionary<string,Warudo.MapTile>.this[string]' because it is not a variable
Run Code Online (Sandbox Code Playgroud)
为什么我不能在字典内的结构中更改值?
是否可以使用Java作为Java的脚本语言?或者也许以某种方式在运行时将java脚本编译成java二进制文件?我确实试过搜索但除了一些黑客之外找不到任何全面的东西......
我有使用其他语言的经验,例如对于C#我使用lua非常方便,但现在我需要实现最大的性能,因为脚本的调用大约是每帧1.000.000.
所以我认为将java本身作为java程序的脚本语言,应该为我提供最好的性能和兼容性.
有什么建议?
是否可以在以下方面做类似的事情C#:
public class MyClass implements ClassA extends ClassB
{
}
Run Code Online (Sandbox Code Playgroud)
我需要这个因为:我有两个类,其中一个Interface是我将在我的类中实现的类,但我也想使用另一个类中的方法,这些方法可以在我的类中使用.
所以我需要在数据库中存储IP地址,但是将它们存储为stings并不是非常有效并且对我的目的来说不太方便.
所以...我怎样才能在php中将ip转换为整数,尽可能少处理,因为它每天会完成数百万次.
当然,我怎么能从integet转换回ip?
我知道这是可以一派,有一些简单的解决办法-但我要求的最快的方式,不只是为了"做X,你会得到Y",因为它实际上是很容易的事.
今天是个好日子!
我的问题是:我需要在类中重载标准get和设置静态变量...但是在php中没有提供这样的功能...它在2008年被问到但仍未实现...同样适用于readonly ...
我的问题:有没有办法让静态属性可以从外部读取,但是可以防止修改?
echo aaa::$qwe; //<--- echoes value of $qwe
aaa::$qwe = '666'; //<--- throws an error because variable is protected from modification
Run Code Online (Sandbox Code Playgroud)
我不能使用const,因为一些变量包含数组.
也许有一些解决方法?
是的,我知道我可以把它变成aaa :: Get('qwe'),但这并不好......
到目前为止,我有一个简单的类包装python引擎(IronPython)供我使用.虽然代码看起来很大,但它非常简单,所以我在这里复制它以便更清楚地解决我的问题.
这是代码:
public class PythonInstance
{
ScriptEngine engine;
ScriptScope scope;
ScriptSource source;
public PythonInstance()
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
}
public void LoadCode(string code)
{
source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
source.Compile();
}
public void SetVariable(string key, dynamic variable)
{
scope.SetVariable(key, variable);
}
public void RunCode()
{
source.Execute(scope);
}
public void CallFunction(string function)
{
//?????? no idea what to call here
}
}
Run Code Online (Sandbox Code Playgroud)
所以,它工作得很好,但它只允许我一次执行所有python脚本......但我想做的是能够从pythos脚本中调用特定的函数.
所以,我的问题是:如何在加载的脚本中调用特定函数?
我试图找到一些信息或教程,但遗憾的是找不到任何东西.
我正在学习3D编程,我决定制作一个非常简单的"引擎",你可以在地图上飞行等等.只有墙壁的基本渲染.
所以,我在想 - 如何保存关卡以及如何编辑它.我也不想为它编辑,因为它只是一个学习项目,而不是一个真正的游戏.所以,我正在寻找这种级别的格式:UDMF http://zdoom.org/wiki/Universal_Doom_Map_Format虽然它适用于完全不同类型的游戏,但它仍然可以满足我的需求.指定顶点,地板,天花板位置等.因此,基本的2.5D几何体,可以很容易地解释为3D空间,这对我的目的来说已经足够了.还有很多编辑(主要原因).
但是,我确实意识到这不是最好的解决方案,而是一种解决方法.
所以,我的问题是:有没有"开放"地图格式和"开放"编辑器,我可以用于我的引擎/游戏?
UPD:我正在使用C#和XNA,如果这很重要的话.
如何使用xpath从节点内部获取文本?
现在我这样做:
$temp= $content->xpath('qwe/qwe');
$temp = each($temp[0]);
return $temp['value'];
Run Code Online (Sandbox Code Playgroud)
但正如你可以看到它远没有很好的解决方案:(
在c#中它很简单
public string readXmlVar(string xpath)
{
XmlNode xmlNode = xml.SelectSingleNode(xpath);
return xmlNode.InnerText;
}
Run Code Online (Sandbox Code Playgroud) 快问.(我无法在任何地方找到关于此的文档)
当你这样做:
Texture2D t1;
t1 = content.Load<Texture2D>("some texture");
Texture2D t2;
t2 = t1;
Run Code Online (Sandbox Code Playgroud)
它是创建引用还是实际复制纹理?
我想知道它,所以我可以在实现相关的东西时考虑到它.
关于在java中使用Groovy,我有3个问题.它们都是相关的,所以我只在这里创建一个问题.
1)有:GroovyClassLoader,GroovyShell,GroovyScriptEngine.但使用它们有什么区别?
例如,对于此代码:
static void runWithGroovyShell() throws Exception {
new GroovyShell().parse(new File("test.groovy")).invokeMethod("hello_world", null);
}
static void runWithGroovyClassLoader() throws Exception {
Class scriptClass = new GroovyClassLoader().parseClass(new File("test.groovy"));
Object scriptInstance = scriptClass.newInstance();
scriptClass.getDeclaredMethod("hello_world", new Class[]{}).invoke(scriptInstance, new Object[]{});
}
static void runWithGroovyScriptEngine() throws Exception {
Class scriptClass = new GroovyScriptEngine(".").loadScriptByName("test.groovy");
Object scriptInstance = scriptClass.newInstance();
scriptClass.getDeclaredMethod("hello_world", new Class[]{}).invoke(scriptInstance, new Object[]{});
}
Run Code Online (Sandbox Code Playgroud)
2)加载groovy脚本的最佳方法是什么,以便它以编译的形式保留在内存中,然后我可以在需要时调用该脚本中的函数.
3)如何将我的java方法/类暴露给groovy脚本,以便它可以在需要时调用它们?