Kineticjs을 사용하여 래스터를 그립니다. 이것은 Kinetic.Rect를 사용하여 작동합니다. 이제 Kinetic.Rect 이외의 다른 개체를 사용하고 싶습니다. 이 객체에서 나는 래스터에서 위치의 x와 y를 저장할 수 있어야합니다. 나는 다음과 같은 코드를 가지고 :Kinetic.Rect의 고유 한 방법
var tile = new Kinetic.Rect({
width: drawWidth,
height: drawHeight,
stroke: 'black',
fill: 'grey',
x: x,
y: j * drawHeight
});
에 : 어떻게 든
var tile = new Tile(j, i, false, {
width: drawWidth,
height: drawHeight,
stroke: 'black',
fill: 'grey',
x: x,
y: j * drawHeight
});
는 config
function Tile(rasterX, rasterY, occupied, config) {
Kinetic.Rect.call(this, config);
this.rasterX = rasterX;
this.rasterY = rasterY;
this.occupied = occupied;
}
Tile.prototype = new Kinetic.Rect();
Tile.prototype.constructor = Tile;
는 지금은 (이 작품)에서 작성 Kinetic.Rect의 코드를 변경 생성 된 모든 타일의 x와 y가 동일하기 때문에 Kinetic.Rect 생성자에 올바르게 전달되지 않습니다 (캔바스의 오른쪽 하단 모서리). 그러나 색상이 있습니다.
흠 개체를 확장하는 방법이다? 대신 Tile.prototype = Object.create (Kinetic.Rect.prototype);를 사용하여 상속을 시도하십시오. – plalx
고마워요! 그게 효과가 있었어. 답변으로 게시 할 수 있습니까? 그리고 Object.create와 my code의 차이점을 설명하십시오. – Klaasvaak