问题
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