赞 | 58 |
VIP | 37 |
好人卡 | 59 |
积分 | 12 |
经验 | 66255 |
最后登录 | 2023-5-29 |
在线时间 | 1017 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1232
- 在线时间
- 1017 小时
- 注册时间
- 2011-4-30
- 帖子
- 1516
|
- //拍摄
- SceneManager.snap = function() {
- return Bitmap.snap(this._scene);
- };
- //拍摄 为了背景
- SceneManager.snapForBackground = function() {
- //背景图片 设置为 拍摄
- this._backgroundBitmap = this.snap();
- //背景图片 模糊
- this._backgroundBitmap.blur();
- };
- //背景图片
- SceneManager.backgroundBitmap = function() {
- return this._backgroundBitmap;
- };
复制代码
- Bitmap.snap = function(stage) {
- var width = Graphics.width;
- var height = Graphics.height;
- var bitmap = new Bitmap(width, height);
- var context = bitmap._context;
- var renderTexture = new PIXI.RenderTexture(width, height);
- if (stage) {
- renderTexture.render(stage);
- stage.worldTransform.identity();
- }
- if (Graphics.isWebGL()) {
- var gl = renderTexture.renderer.gl;
- var webGLPixels = new Uint8Array(4 * width * height);
- gl.bindFramebuffer(gl.FRAMEBUFFER, renderTexture.textureBuffer.frameBuffer);
- gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels);
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
- var canvasData = context.getImageData(0, 0, width, height);
- canvasData.data.set(webGLPixels);
- context.putImageData(canvasData, 0, 0);
- } else {
- context.drawImage(renderTexture.textureBuffer.canvas, 0, 0);
- }
- bitmap._setDirty();
- return bitmap;
- };
复制代码
- Bitmap.prototype.blur = function() {
- for (var i = 0; i < 2; i++) {
- var w = this.width;
- var h = this.height;
- var canvas = this._canvas;
- var context = this._context;
- var tempCanvas = document.createElement('canvas');
- var tempContext = tempCanvas.getContext('2d');
- tempCanvas.width = w + 2;
- tempCanvas.height = h + 2;
- tempContext.drawImage(canvas, 0, 0, w, h, 1, 1, w, h);
- tempContext.drawImage(canvas, 0, 0, w, 1, 1, 0, w, 1);
- tempContext.drawImage(canvas, 0, 0, 1, h, 0, 1, 1, h);
- tempContext.drawImage(canvas, 0, h - 1, w, 1, 1, h + 1, w, 1);
- tempContext.drawImage(canvas, w - 1, 0, 1, h, w + 1, 1, 1, h);
- context.save();
- context.fillStyle = 'black';
- context.fillRect(0, 0, w, h);
- context.globalCompositeOperation = 'lighter';
- context.globalAlpha = 1 / 9;
- for (var y = 0; y < 3; y++) {
- for (var x = 0; x < 3; x++) {
- context.drawImage(tempCanvas, x, y, w, h, 0, 0, w, h);
- }
- }
- context.restore();
- }
- this._setDirty();
- };
复制代码 |
|