Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我需要阵列中的这些物体以随机速度移动。_Javascript_Oop - Fatal编程技术网

Javascript 我需要阵列中的这些物体以随机速度移动。

Javascript 我需要阵列中的这些物体以随机速度移动。,javascript,oop,Javascript,Oop,这是指向我的github的链接。我需要让allEnemies数组中的物品以随机速度移动。现在他们都在以同样的速度移动。任何关于如何实现这一点的想法都将不胜感激 嗨,我不是JS方面的专家,但像这样的东西应该有用: var Enemy = function(x, y) { // Variables applied to each of our instances go here, // we've provided one for you to get started // The image/sp

这是指向我的github的链接。我需要让allEnemies数组中的物品以随机速度移动。现在他们都在以同样的速度移动。任何关于如何实现这一点的想法都将不胜感激

嗨,我不是JS方面的专家,但像这样的东西应该有用:

var Enemy = function(x, y) {
// Variables applied to each of our instances go here,
// we've provided one for you to get started
// The image/sprite for our enemies, this uses
// a helper we've provided to easily load images
this.sprite = 'images/enemy-bug.png';
this.x = x;
this.y = y;
this.speed = Math.floor(Math.random() * MaxSpeedValue) + MinSpeedValue; 

}

请在问题中包含您要询问的代码,而不是在一个链接中,该链接一旦有人回答您的问题,无疑会过时,从而使这个问题在将来对任何人都没有用处-您的答案的关键字是随机的-公平地说,如果javascript有某种随机数,仅在github上就可以看到此代码的数千个化身