我有以下问题:我正在尝试编写一个javascript游戏,并且该字符由箭头键控制.
问题是,当按下按键时,在第一次按键和重复按下之间存在短暂的延迟.
此外,当按下"右箭头键"并按住它,然后按下"向上箭头键"时,角色不会移动到右上角,而是停止向右移动并开始向上移动.
这是我正在使用的代码:
<body onLoad="Load()" onKeyDown="Pressed(event)">
Run Code Online (Sandbox Code Playgroud)
function Pressed(e) {
cxc = e.keyCode;
if(cxc == 37)
Move(-1,0);
if(cxc == 38)
Move(0,-1);
if(cxc == 39)
Move(1,0);
if(cxc == 40)
Move(0,1);
}
有没有人有想法?
我正在尝试从外部JavaScript导入一组坐标.我必须在构造函数中包含大约78.740个元素,但firefox只会抛出一个错误:
"太多的构造函数参数"
是否有人有任何想法?
这是我的代码:
function CreateArray() {
return new Array(
...
...
...
78.740 elements later
...
); }
我在JS中有一个16个台球阵列,希望用它的方向和速度顺畅地移动每个球.
为此,我设置了一个定时器,UpdateThis()每隔42ms 调用一次(24 fps).
问题是UpdateThis()需要53毫秒作为萤火虫状态.
现在UpdateThis迭代每一个球和电话UpdateBall(ball).
我认为那里存在问题.
UpdateBall看起来像这样:
function UpdateBall(ball)
{
if(ball.direction.x != 0 && ball.direction.y != 0) {
//ball moving!
for(var i = 0; i < balls.length; i++) {
//CheckCollision(ball, balls[i]); //even without this it takes 53 ms!
}
var ps = VAdd(ball.position, VMul(ball.direction, ball.speed)); //Multiply Direction with speed and add to position!
if(ps.x < Bx || ps.y < By || ps.x > Bw || ps.y > Bh) { //Bounce off …Run Code Online (Sandbox Code Playgroud) 我正在尝试解析一些ddump文件,你能帮我加速算法吗?
每个循环需要216毫秒!! 这太过分了.我希望每循环大约40-50毫秒.也许通过使用RegExp?
这是我的algrithm:
while (pos < EntireFile.Length && (/*curr = */EntireFile.Substring(pos, EntireFile.Length - pos)).Contains(" class"))
{
w.Reset();
w.Start();
pos = EntireFile.ToLower().IndexOf(" class", pos) + 6;
int end11 = EntireFile.ToLower().IndexOf("extends", pos);
if (end11 == -1)
end11 = EntireFile.IndexOf("\r\n", pos);
else
{
int end22 = EntireFile.IndexOf("\r\n", pos);
if (end22 < end11)
end11 = end22;
}
//string opcods = EntireFile.Substring(pos, EntireFile.Length - pos);
string Cname = EntireFile.Substring(pos, end11 - pos).Trim();
pos += (end11 - pos) + 7;
pos = EntireFile.IndexOf("{", pos) +1; …
我有一个object[]containig一些值。我想从中提取信息,但是我无法将数组(a WeakReference)中的第二个对象强制转换为IList,其中T为数组中的第三个值。
看一下我的代码:
object[] vals = GetValues(); //vals[2] = WeakReference, vals[3] = Type of T, vals[4] = index in the list
IList<((Type)vals[3])> list = (IList<((Type)vals[3])>)(((WeakReference)vals[2]).Target); //This line does not even compile, seems like I'm doing something wrong..
object oo = list.ElementAt((int)vals[4]);
//Do something with oo...
Run Code Online (Sandbox Code Playgroud)
有什么建议可以将WeakReference的目标转换为T = vals [3]的IList接口吗?
您好
我有一个主应用程序将在./plugin目录中有一些插件.
每个插件都是.NET dll,应该具有命名空间"Plugin"和实现主应用程序中定义的IPlugin接口的类"MainClass".
我的问题是,我不知道我怎么能分享横跨主应用程序和每个插件都相同的接口没有一个using参考?
主app类的一部分:
object oo = Assembly.LoadFile(path).CreateInstance("Plugin.MainClass");
IPlugin pp = (IPlugin)oo; //Fails if I define the interface in the main app and the plugins
Run Code Online (Sandbox Code Playgroud)
和第一个插件的一部分:
namespace Plugin
{
public class MainClass : IPlugin //I cannot reference the interface in the main app?
{
public string getName()
{
return "Plugin 1";
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个浮动持有一个非常重要的值,必须非常精确.
我遇到的问题是我正在改变浮点数的值只有+和 - (这里没有除法).
将值改变约20次后,该值不是预期的0.05,其为0.0499989.
为什么是这样?我没有施放漂浮物,我不是它,但它神奇地从0.05变为0.049989.
我试过Math.Round(value, 2);但它也没有返回0.05.我现在应该怎么做??
在转换引用时,似乎编译器尝试将Derived类转换为它,Base并且根本不使用自定义转换.尽管如此,这仍然完美无缺.
例:
#include <iostream>
class Base {
public:
int fn() {
return 42;
}
};
class Derived : private Base {
public:
operator Base&() {
return *dynamic_cast<Base*>(this);
}
operator Base*() {
return dynamic_cast<Base*>(this);
}
};
int main() {
Derived d;
Derived &dRef = d;
std::cout<<static_cast<Base&>(dRef).fn()<<std::endl; // <-- error: non-reachable base >>Base<< of >>Derived<<
std::cout<<static_cast<Base*>(d)->fn()<<std::endl; // OK -> "42"
}
Run Code Online (Sandbox Code Playgroud)
为什么不能像这样使用自定义转换?是否有可能实现预期的行为(使用引用"向上转换"到不可到达的基础)?
您好我想通过C#计算吞吐量HttpWebRequest.
我想在运行时请求一个大文件(500KB)System.Diagnostics.Stopwatch.
然后我可以计算KB/s速率.我现在有两个问题:
1.这有多准确?我可以依赖它,还是应该使用其他方法?
2.如何在可以硬编码的URL上托管文件,而不必担心服务器端问题?我可以以某种方式使用具有如此大小的文件,最好是谷歌或微软页面?
先谢谢你,
Alex
c# ×5
javascript ×3
.net ×2
casting ×2
windows ×2
algorithm ×1
arguments ×1
bandwidth ×1
c++ ×1
constructor ×1
events ×1
forms ×1
game-physics ×1
generics ×1
inheritance ×1
ip ×1
parsing ×1
plugins ×1
refactoring ×1
reference ×1
templates ×1
winforms ×1