
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
@rapideditor/pixi-dashed-line
Advanced tools
đź‘‹
This is just a copy of the awesome pixi-dashed-line repo that can be found at https://github.com/davidfig/pixi-dashed-line
You probably want that instead.
We are keeping this copy pinned to the latest version of PixiJS, to avoid issues with bundling multiple versions of PixiJS.
A pixi.js implementation to support dashed lines in Graphics.
https://davidfig.github.io/pixi-dashed-line (source code)
DashLine.DashLineOptions = {
useTexture?=false - whether to use a texture or moveTo/lineTo (see notes below in README.md)
dashes?=[10, 5] - an array holding one or more [dash, gap] entries, eg, [10, 5, 20, 10, ...])
width?=1 - width of the dashed line
color?=0xffffff - color of the dashed line
alpha?=1 - alpha of the dashed line
options.cap? - add a LINE_CAP style to dashed lines (only works for useTexture: false)
options.join? - add a LINE_JOIN style to the dashed lines (only works for useTexture: false)
options.alignment? - change alignment of lines drawn (0.5 = middle, 1 = outer, 0 = inner)
}
Moves cursor to location
Draws a dashed line. If closePath = true, then lineTo will leave a proper gap if its destination is the first point (ie, if this line closes the shape)
where x,y is the center of circle, and points are the number of points used to draw the circle; matrix is applied before the draw (this adds a shape-specific transform to pixi's DisplayObject transforms)
where x,y is the center of ellipse, and points are the number of points used to draw the ellipse; matrix is applied before the draw (this adds a shape-specific transform to pixi's DisplayObject transforms)
draws a dashed rectangle; matrix is applied before the draw (this adds a shape-specific transform to pixi's DisplayObject transforms)
draws a dashed polygon; matrix is applied before the draw (this adds a shape-specific transform to pixi's DisplayObject transforms)
changes line style to the proper dashed line style -- this is useful if the graphics element's lineStyle was changed
import { DashLine } from 'pixi-dashed-lines'
...
const g = stage.addChild(new Graphics())
const dash = new DashLine(g, {
dash: [20, 10],
width: 5,
color: 0xff0000,
})
// draws a dashed triangle
dash.moveTo(0, 0)
.lineTo(100, 100)
.lineTo(0, 100)
.lineTo(0, 0)
For most use-cases, the lineTo/moveTo (options.useTexture = false
) is better because it provides a more accurate implementation and supports cap and join styles.
The texture-based approach (options.useTexture = true
) is useful when the geometry is very large or very small as Graphics does not handle those cases well (see https://www.html5gamedevs.com/topic/24876-weird-lines-when-using-extreme-coordinate-values/). You'll know you need this if zooming in and out on the dashed line causes out of memory errors :)
options.useTexture=true
does not use pixi.js's line joins and caps for connecting lines (see https://mattdesl.svbtle.com/drawing-lines-is-hard): instead it uses Graphics.lineTextureStyle
to supply a texture to draw the dashed lines. The texture needs a custom matrix to properly rotate the dash based on the angle of the next line (and to translate the texture so it starts properly (see https://www.html5gamedevs.com/topic/45698-begintexturefill/)). Without the matrix, the dash's length will change as the line's angle changes.
Regrettably, pixi.js does not provide a mechanism to change the matrix of a texture without breaking the current line with a moveTo command. (This was my key insight that finally got this working. I banged my head many hours trying to figure out why the texture did not rotate properly. The answer was that you have to moveTo before changing the matrix.)
Ideally, the dashed line functionality should be built directly into pixi.js's Graphics line drawing module w/logic that separates the triangles of the dashed line to take into account changes in the angle of the line. I thought about adding it, but decided the amount of work was not worth it. (Especially since the use case for useTexture is limited to strange Graphics geometries.) Maybe someone does a different calculus and adds this feature directly into pixi.js and makes this library obsolete.
MIT License (c) 2021 David Figatner
FAQs
Pixi.js dashed lines
We found that @rapideditor/pixi-dashed-line demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.