Attach canvas drawed line to scene in Android

好久不见. 提交于 2020-01-07 06:41:06

问题


I would like to attach a line drawed with canvas to a Scene. I'm using andengine library.

I know that andengine provides line objects that can be draw and attached to a scene, but this is not an option for me because i'm trying to make a pretty glow line.

This is how a andengine line is attached to the scene.

public class MainActivity extends SimpleBaseGameActivity implements OnClickListener {
//--Declaration and implementation of all overrides, etc.--
    @Override
        protected Scene onCreateScene() {
        final Line line = new Line(50,75,CAMERA_WIDTH,89,20,vbom);
        line.setColor(248, 255, 255, 255);
        line.setLineWidth(5f);
        final Line line2 = new Line(50,75,CAMERA_WIDTH,89,50,vbom);
        line2.setColor(235, 74, 138, 255);
        line2.setLineWidth(10f);
        scene.attachChild(line2);
        scene.attachChild(line);
        return scene;
    }
}

This is how it looks like and as you can see, it dont seems pretty good or maybe is the fact that i am not applying proper styles, i'll be happy of you notified me.

But if i try with canvas, it looks a perfect glow line.

public class DrawingView extends View {
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.BLACK);

    Paint _paintSimple = new Paint();
    _paintSimple.setAntiAlias(true);
    _paintSimple.setDither(true);
    _paintSimple.setColor(Color.argb(248, 255, 255, 255));
    _paintSimple.setStrokeWidth(5f);
    _paintSimple.setStyle(Paint.Style.STROKE);
    _paintSimple.setStrokeJoin(Paint.Join.ROUND);
    _paintSimple.setStrokeCap(Paint.Cap.ROUND);

    Paint _paintBlur = new Paint();
    _paintBlur.set(_paintSimple);
    _paintBlur.setColor(Color.argb(235, 74, 138, 255));
    _paintBlur.setStrokeWidth(10f);
    _paintBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));

    canvas.drawLine(100, 150, 400, 150, _paintBlur);
    canvas.drawLine(100, 150, 400, 150, _paintSimple);
    }
}

I wanted the perfect glow line to be attached to my scene. I'm doing that way because i'm also using OnClickListener with sprites objects. Any suggestion or help would help me a lot. Thanks.

来源:https://stackoverflow.com/questions/30695622/attach-canvas-drawed-line-to-scene-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!