1
0
Fork 0

[client] Get chunks to account for position on canvas

This commit is contained in:
Starbeamrainbowlabs 2017-06-11 21:47:38 +01:00
parent 6a0d3180a7
commit 00117a35a9
2 changed files with 9 additions and 6 deletions

View File

@ -40,20 +40,23 @@ class Chunk
render(canvas, context) render(canvas, context)
{ {
var planeSpaceRef = this.chunkRef.inPlaneSpace(this.size);
context.save(); context.save();
context.translate(planeSpaceRef.x, planeSpaceRef.y);
for(let line of this.lines) for(let line of this.lines)
{ {
context.beginPath(); context.beginPath();
context.moveTo( context.moveTo(
line.Points[0].x - this.chunkRef.inPlaneSpace(this.size).x, line.Points[0].x - planeSpaceRef.x,
line.Points[0].y - this.chunkRef.inPlaneSpace(this.size).y line.Points[0].y - planeSpaceRef.y
); );
for(let i = 1; i < line.Points.length; i++) for(let i = 1; i < line.Points.length; i++)
{ {
context.lineTo( context.lineTo(
line.Points[i].x - this.chunkRef.inPlaneSpace(this.size).x, line.Points[i].x - planeSpaceRef.x,
line.Points[i].y - this.chunkRef.inPlaneSpace(this.size).y line.Points[i].y - planeSpaceRef.y
); );
} }

View File

@ -12,8 +12,8 @@ class ChunkReference extends Vector
/** /**
* Returns a plain Vector of this chunk reference in plane space. * Returns a plain Vector of this chunk reference in plane space.
* @param {number} chunkSize The size of the chunk this ChunkReference refers to. * @param {number} chunkSize The size of the chunk this ChunkReference refers to.
* @return {Vector} This ChunkReference in plane space. * @returns {Vector} This ChunkReference in plane space.
*/ */
inPlaneSpace(chunkSize) inPlaneSpace(chunkSize)
{ {