egret.CustomFilter 範例, 更多請檢視 官方範例
class Main extends eui.UILayer {
protected createChildren(): void {
super.createChildren();
egret.lifecycle.onPause = () => egret.ticker.pause();
egret.lifecycle.onResume = () => egret.ticker.resume();
egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
this.runGame();
}
private async loadResource() {
let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
await RES.loadConfig('resource/default.res.json', 'resource/');
await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
await RES.loadGroup('preload', 0, loadingView);
this.stage.removeChild(loadingView);
}
private async runGame() {
await this.loadResource();
// --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---
const vertexSrc = `
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform vec2 projectionVector;
varying vec2 vTextureCoord;
const vec2 center = vec2(-1.0, 1.0);
void main(void) {
vTextureCoord = aTextureCoord;
gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);
}
`;
const fragmentSrc = `
precision lowp float;
varying vec2 vTextureCoord;
void main(void) {
gl_FragColor = vec4(vTextureCoord.x, vTextureCoord.y, 0.0, 1.0);
}
`;
const img = new eui.Image('bg_jpg');
img.filters = [new egret.CustomFilter( vertexSrc, fragmentSrc )];
this.addChild(img);
}
}
沒有留言:
張貼留言