Question

I'm trying to move a line in erase.js I read some thread with this issue, but nothing works for me. The problem is that, I can manipulate some properties like label position, but not the line position. Just now the creation of my line is:

var result = {};
                //Generation of the line
                result.line = new createjs.Shape();
                result.line.graphics.setStrokeStyle(3);
                result.line.graphics.beginStroke("#000");
                result.line.graphics.moveTo(o[0].__dragger.x + 24 , o[0].__dragger.y);
                result.line.graphics.lineTo(o[1].__dragger.x - 24, o[1].__dragger.y);
                result.line.graphics.endStroke();
                //result.line.shadow = new createjs.Shadow("#000000", 5, 5, 10);



                //Add the neighbours
                result.neighbours = o;

                //Add the label
                result.label = new createjs.Text("line", "", "#000");
                result.label.textAlign = "center";
                result.label.y = 80;
                result.label.x = 200;

                //Add the dragger and extra properties
                result.type = "connector";
                result.__dragger = new createjs.Container();
                if(id == "")
                    result.__dragger.id = "L" + guid();

                result.__dragger.addChild(result.line, result.label);
                stage.addChild(result.__dragger, result.line);

                result.__dragger.on("click",function(evt) {
                    Shape.create("square", [], "Assignament");
                });

                stage.addChild(result.__dragger);
                stage.update();
myShapes.push(result);

If I execute:

myShapes[2].label.y = 200;
myShapes[2].label.x = 300;
stage.addChild(myShapes[2].__dragger);
stage.update();

The position is updated, but if I try with:

myShapes[2].line.graphics.moveTo(300,4000)
stage.addChild(myShapes[2].__dragger);
stage.update();

The object is not updated. Some idea??

Was it helpful?

Solution

I am not sure I understand what you are doing, but here is a thought:

You can't move a line using graphics.moveTo -- that is an instruction to position the drawing API for subsequent path instructions. If you were to line.graphics.lineTo(300,4000), it would draw a line from the last graphic instruction to that coordinate (within the Shape's coordinate system).

To move a Shape, you must set the x and y position of the shape instance (in this case myShapes[2].line)

If you post more info, I can try and assist more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top