Draw a line from one scene object to another


I was wondering if there was a smart way of drawing a line, like it starts from one scene object and end at another scene object, maybe at it's anchor point.

To explain better I think I want to draw the displacement line between two sceneobjects. Is it possible to do this in an easier way in WADE?

Thanks and help would be really appreciated!

All 2 Comments

Hi Prajwal

I think the easiest way is to create a sprite that connects the two objects. Then you can use a solid color, a texture or a shader to fill it.

If you have two objects objA and objB then:

var posA = _.a.getPosition();
var posB = _.b.getPosition();
var middlePoint = wade.vec2.scale(wade.vec2.add(posA, posB), 0.5);
var delta = wade.vec2.sub(posB, posA);
var rotation = Math.atan2(delta.y, delta.x);
var lineSprite = new Sprite('procedural_square', 5); // change parameters depending on what you want
lineSprite.setSize(wade.vec2.length(delta), 4); // 4 is the thickness of the line
var lineObject = new SceneObject(lineSprite);



Super thanks for the snippet Gio... Appreciate it!

Post a reply
Add Attachment
Submit Reply
Login to Reply