0

帆布性能

最近我在画布中创建了很多动画,并且由于画布没有事件,您需要根据坐标创建自己的事件系统,简而言之,您需要一个碰撞检测功能。由于大多数代码都很长,我重写了自己的这样做我理解它是多么简单。所以我写了一些游戏代码。

基本上,画布游戏有很多临时数字数组,在大多数情况下,0 到 64,128 或 256 之间的数字就足够了。也许减少并用作倍增器

hitpoints=max*(number/256);

所以我在想如果我将这些值存储到一个arraybuffer

var array = new Float64Array(8);
array[0] = 10;
//....

示例:(我就是这样做的......如果你知道更好的东西,请随时告诉我)

//Usable ammonition
var ammo=[
 ['missiles',dmg,range,radius,red,green,blue,duration],
 //all appart the first are numbers between 0 and 255
 ['projectile',dmg,range,radius,red,green,blue,duration]
]
//Flying ammonition
//this is created inside the canvas animation everytime you shoot.
var tempAmmo=[
 [id,timestarted,x,y,timepassed] //these are all integers.
 // the longest is probably  the timestamp
]
// i could add the ammo numbers to the tempAmmo (which is faster):
[id,timestarted,x,y,timepassed,dmg,range,radius,red,green,blue,duration]

// then i do the same double array for enemies and flyingEnemies.

将所有内容存储在 arrabuffers 中不是更好吗?

我的想法(如果我错了,请纠正我):

arraybuffers是二进制数据,

它们的渲染速度应该更快,内存应该更小

现在,如果这两种观点是正确的,我该如何正确地创建一个像所描述的那样的数组结构,也许选择正确的数组类型?

注意:在我的情况下,我使用的是二维数组。而且我不想使用对象。

4

0 回答 0