This repository has been archived by the owner on Dec 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
[3.0] 2: SurfaceRendererComponent
Yuya Matsuo edited this page Sep 27, 2016
·
1 revision
surface
attribute defines how to draw surface on entity's geometry. surface
takes CSS like string parameters.
Example:
<entity surface="renderer: @drawable/my_image"/>
<entity surface="renderer: @layout/my_view"/>
<entity surface="renderer: com.custom.MyCanvasRenderer"/>
Attribute | Description |
---|---|
renderer | It takes @drawable/xxx , @layout/xxx , or class name. @drawable/xxx and @layout/xxx are for rendering static texture. Class name is for rendering dynamic texture (such as animation). |
If you want to render static texture (simple image) and it is bundled in res
directory, use renderer: @drawable/xxx
or renderer: @layout/xxx
.
If you want to render dynamic texture, you should create class inherits from SurfaceRendererComponent.CanvasRenderer
and set it to renderer
.
import org.meganekkovr.SurfaceRendererComponent;
public class MyRenderer extends SurfaceRendererComponent.CanvasRenderer {
// Renderer must have default constructor so define it.
// Call super(width, height) with required texture size.
public PointerRenderer() {
super(64, 64);
// Init for rendering
// Usually you would create Paint and call setColor, setStrokeWidth, etc...
}
@Override
protected boolean render(Canvas canvas) {
// Clear previous image
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
// Draw something
// returning true means that no need to redraw on next frame update.
// render(canvas) is not called until invalid() is called in the future.
return true;
}
public void setSomeValue(float value) {
// If some values are changed and redraw is required,
// call invalidate()
// this.value = value;
invalidate();
}
}