-
Notifications
You must be signed in to change notification settings - Fork 65
Pixel perfect collision? #112
Comments
WebGL + pixel perfect collision will be very slow thing. I dont think that any GL engine can support it. |
@ivanpopelyshev If you queried the pixels directly from the shader, but you could also look at the png file after transforming your point with the matrix from the texture, or cache the bitmap data, or any number of things. I guess I'll be writing that. :/ Most applications need some at least some alpha testing, even for just buttons, and almost all games require it. I'd say this hardly usable without it. |
if I recall correctly, you can generate a bitmap array this way : `var lModel : Container = "insert your display object reference" lCanvas.render( lModel); var lImageData : ImageData = lCanvas.context.getImageData( 0, 0, lModel.width, lModel.height);` And so on, you can work on the ImageData instance. This worked for me at pixi 4.0.2, I hope it still works :) You may generate your bitmap datas before you use them, as I believe it's a bit expensive to generate them at the fly ... |
Oh, we didnt close this? OK, here's answer for v5: https://github.com/pixijs/pixi.js/wiki/v5-Hacks#pixel-perfect-interaction |
How do we achieve pixel perfect collision? This seems to be a problem with pixijs, but the common workarounds using WebGLExtract seem to not have externs. I'm considering creating a separate canvas element and using it to get pixel data like this, is this recommended?
EDIT: To clarify my situation, I need to get alpha tolerant pixel testing on animations, and building hitArea polygons isn't really feasible in my setup unless they could be done at runtime.
EDIT 2: I've found this work around for now.
var pixel:Array<Float> = untyped __js__('({0}).extract.pixels({1}).slice({2}, {3})', app.renderer, renderTexture, startInd, startInd+4);
EDIT 3: This actually still won't work because you can't clear RenderTextures on canvas without renderer.clearRenderTexture which is seemingly webgl only.
Can pixi js realistically support pixel colour testing? I've take the feature for granted, but it seems the tech might not be there yet or something??
The text was updated successfully, but these errors were encountered: