2
我試着爲剪切紋理創建蒙版。用戶在屏幕上移動手指,以及何時會彈起手指遮罩。我的問題,用戶有很長一段時間移動在屏幕上了手指之後,面膜開始創建,和我有ANR符合PolygonRegion創建anr
PolygonRegion polyReg = new PolygonRegion(textRegion, coord);
其中座標是浮點數組和textRegion它與紋理對象TextureRegion其中需要畫。當用戶長時間在屏幕上移動時會出現問題。第一次我認爲PolygonRegion不能解決很多問題,但是在瞭解了它不算點問題之後(有時候我有160點的anr,有時候我沒有1000點的anr)。也許有人採取同樣的問題,並可以說它可能是什麼。
代碼:
if(maskBufferer != null){
maskBufferer.dispose();
}
maskBufferer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, true);
mask = createMaskImageMask(aspectRatioCrop, maskBufferer);
...
private Texture createMaskImageMask(boolean aspectRatioCrop, FrameBuffer maskBufferer) {
maskBufferer.begin();
Gdx.gl.glClearColor(COLOR_FOR_MASK, COLOR_FOR_MASK, COLOR_FOR_MASK, ALPHA_FOR_MASK);
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);
float[] coord = null;
coord = mCoodrinateArray.getCoodrinatesInScreenSize();
mCoodrinateArray.clean();
PolygonRegion polyReg = new PolygonRegion(new TextureRegion(new Texture(Gdx.files.internal(texturePolygon))),
coord);
PolygonSprite poly = new PolygonSprite(polyReg);
PolygonSpriteBatch polyBatch = new PolygonSpriteBatch();
polyBatch.begin();
poly.draw(polyBatch);
polyBatch.end();
maskBufferer.end();
texture.dispose();
polyBatch.dispose();
return maskBufferer.getColorBufferTexture();
}
在onMove代碼:
Vector3 vec = MathUtils.toGlFromScreenV3(detector.getCurrEvent().getX(), detector.getCurrEvent().getY(), mWidth, mHeight);
mCoodrinateArray.addCoordinate(vi.x, vi.y);