最近在用pixi绘制地图的时候需要做带箭头的线,用来从一个点执行另一个点,表示此段路线可行,但是发现pixie是没有自带的绘制带箭头线段的,那就只能自己绘制了,在此记录一下,pixi底层是用的canvas,所以绘图和方法和canvas很像,先通过PIXI创建Graphics对象。,绘制一条线段,这里绘制从(50,50)到(350,350)的线段颜色设置为黑色
然后开始给这个线段绘制箭头,绘制箭头的功能可以封装为一个方法,箭头的位置,朝向等,由于线段的朝向不确定性,箭头也需要根据线段的方向来算,通过两个点的夹角方向获取到箭头的朝向,
然后就可以根据需要来给线段绘制箭头,其中dx的值是startX-endX,dy的值是startY-endY获取到,
最终结果如下: