Skip to content
Snippets Groups Projects
Commit 8df696b2 authored by Manuel Herrmann's avatar Manuel Herrmann
Browse files

now compatible with translation of layers

parent 9c1e1055
No related branches found
No related tags found
No related merge requests found
......@@ -17,8 +17,8 @@ function Char(svg, options) {
Char.prototype.findSpawn = function() {
// [1320, svgFlipY(svg[0][0], 500)]
var spawn = this.svg.select("#player_spawn");
var b = spawn[0][0].getBBox();
return [b.x, b.y];
var bbox = spawn[0][0].getBBox();
return Vec.add(getTranslation(this.svg[0][0], spawn[0][0]), [bbox.x, bbox.y]);
}
Char.prototype.animate = function() {
}
......
......@@ -18,11 +18,13 @@ PathFinder.prototype.scanWalkables = function() {
if (!self.noWalkNode && label == "NOWALK")
self.noWalkNode = this;
});
var walkTranslation = getTranslation(this.svg[0][0], this.walkNode);
d3.select(self.walkNode).selectAll('path').each(function() {
self.walkNodes.push(new Path(this.getAttribute("d")));
self.walkNodes.push(new Path(this.getAttribute("d"), walkTranslation));
});
var noWalkTranslation = getTranslation(this.svg[0][0], this.noWalkNode);
d3.select(self.noWalkNode).selectAll('path').each(function() {
self.noWalkNodes.push(new Path(this.getAttribute("d")));
self.noWalkNodes.push(new Path(this.getAttribute("d"), noWalkTranslation));
});
}
PathFinder.prototype.generateRaster = function() {
......
......@@ -7,12 +7,17 @@ function showCoords(x, y) {
function svgFlipY(svg, y) {
return svg.getBBox().height - y;
}
function getTranslation(svg, node) {
var matrix = svg.getTransformToElement(node);
return [matrix.e, matrix.f];
}
function Path(svgPathData) {
function Path(svgPathData, offset) {
this.edges = [];
var currentPosition = [0,0];
if (!offset) offset = [0,0];
var relativeCommand = true;
var currentCommand = 'm';
......@@ -32,7 +37,7 @@ function Path(svgPathData) {
if (isNumber) {
currentPosition = part.split(",");
for (var i = 0; i < currentPosition.length; ++i)
currentPosition[i] = (relativeCommand ? lastPosition[i] : 0) + Number(currentPosition[i]);
currentPosition[i] = offset[i]+(relativeCommand ? lastPosition[i] : 0) + Number(currentPosition[i]);
if (currentCommand == 'l')
this.edges.push([lastPosition, currentPosition]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment