HTML画布重新着色/编辑形状或数组

HTML canvas recolour/edit a shape or array?

本文关键字:数组 编辑 布重新 HTML      更新时间:2023-09-26

我正在构建一个实时画布点击游戏,并且几乎完成了。我需要更改画布绘制元素的颜色。我听说这是做不到的。我有一个变量,包含点击形状的这些属性,用于两个客户端:

{ x: 446.48232363630086,
  y: 279.37327971844934,
  dx: 2.829614687943831,
  dy: -3.0215198849327862,
  rad: 26,
  color: 'rgb(146,25,122)' }

我有另一个变量包含一种新的颜色,如果无法更改画布上绘制的东西的颜色,我可以编辑数组中的对象吗?这将使我当前的drawShape函数重新绘制更改后的形状?这是我以前的单人游戏代码,供参考。https://jsfiddle.net/a9b3rm5u/5/感谢

我发现了:

var i = data.shapeRemoval;//object data
var c = data.colours; // colour data
var r = c;
shapes.splice(i,1); // removes old object from array
i.color = c; // replaces the color in the object for the variable C
shapes.push(i)// pushes to array