Skip to main content
Inspiring
August 16, 2015
Question

Move graphics points at runtime?

  • August 16, 2015
  • 2 replies
  • 302 views

Hello, how to get the graphics points and change the values of its x&y at runtime?

for example:

var moveToX:Array = [50, 200];

var moveToY:Array = [0, 0];

var lineToX:Array = [100, 0, 50, 250, 150, 200];

var lineToY:Array = [100, 100, 0, 100, 100, 0];

var _points:Array = [];

var linesIndex:int = 0;

var myShape:Shape = new Shape();

myShape.graphics.lineStyle(3, 0x000000, .2);

myShape.graphics.beginFill(0x666666, .1);

  

for (var i:uint = 0; i< moveToX.length; i++)

{  

    var _point:Point = new Point(moveToX, moveToY);

    _points.push(_point);

}

for (var p:uint = 0; p< _points.length; p++)

{

        myShape.graphics.moveTo(_points

.x, _points

.y);

      

        myShape.graphics.lineTo(lineToX[linesIndex], lineToY[linesIndex]);

        myShape.graphics.lineTo(lineToX[linesIndex+1], lineToY[linesIndex+1]);

        myShape.graphics.lineTo(lineToX[linesIndex+2], lineToY[linesIndex+2]);

        linesIndex +=3;

}

myShape.x = 0;

myShape.y = 0;

addChild(myShape);

// Now I want to change the points values and update the shape at runtime, but what I am looking for is NOT to clear and redraw it again.. I am trying to apply the changes directly to the same shape because it has a lot of points and lines as the update will be every 2 milliseconds..

So can you help please? Thnaks.

This topic has been closed for replies.

2 replies

nezarovAuthor
Inspiring
August 16, 2015

the update every 25 milliseconds not 2..

kglad
Community Expert
Community Expert
August 16, 2015

you can change the _points array values but that will not change the myShape graphics property.  you need to clear and redraw.

kglad
Community Expert
Community Expert
August 16, 2015

what are you trying to change?  the transform/registration point?

nezarovAuthor
Inspiring
August 16, 2015

I want to change the shape points positions (to do some motion tween for the shape points)