Hey :)!
I am trying to build a round minimap. I do not want to duplication rendering of all game objects, so I decided to add a second Camera.
My Issue: Is there any way to get the Camera Object in a round shape?
The game is an endless generated Map getting chunk data from a nodejs server. So the minimap should stay quite flexible. A camera fits my needs but the shape issue still exists.
I would appreciate help a lot !
EDIT: Found a solution. Enjoy
import Phaser from 'phaser';
export default new Phaser.Class({
Extends: Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline,
initialize:
function CustomPipeline (game)
{
Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline.call(this, {
game: game,
renderer: game.renderer,
fragShader: `
precision mediump float;
uniform sampler2D uMainSampler;
varying vec2 outTexCoord;
void main(void)
{
if (length(outTexCoord.xy - vec2(0.5, 0.5)) > 0.5) {
discard;
} else {
gl_FragColor = texture2D(uMainSampler, outTexCoord);
}
}
`});
}
});
And in the Scene:
this.minimapPipeline = this.game.renderer.addPipeline('Minimap', new
MinimapPipeline(this.game));
this.minimapCamera = new MinimapCamera({
scene: this,
x: 0,
y: 0,
width: 400,
height: 400,
});
this.minimapCamera.setPosition(this.game.scale.width - 240, 40);
this.minimapCamera.setZoom(0.5);
this.minimapCamera.startFollow(this.world.entityManager.get(this.focusEntity));
this.minimapCamera.setRenderToTexture(this.minimapPipeline);
Take care, if you use Zoom, you need to adjust the camera size to it. i.e.:
200x200 target = zoom 0.5 & 400x400 size