mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
Added prerenderclear event to canvas and webgl
This commit is contained in:
parent
426cbe2d95
commit
9eaf661a45
3 changed files with 32 additions and 0 deletions
|
@ -354,6 +354,7 @@ var CanvasRenderer = new Class({
|
|||
* Called at the start of the render loop.
|
||||
*
|
||||
* @method Phaser.Renderer.Canvas.CanvasRenderer#preRender
|
||||
* @fires Phaser.Renderer.Events#PRE_RENDER_CLEAR
|
||||
* @fires Phaser.Renderer.Events#PRE_RENDER
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
@ -369,6 +370,8 @@ var CanvasRenderer = new Class({
|
|||
ctx.globalCompositeOperation = 'source-over';
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
this.emit(Events.PRE_RENDER_CLEAR);
|
||||
|
||||
if (config.clearBeforeRender)
|
||||
{
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
|
26
src/renderer/events/PRE_RENDER_CLEAR_EVENT.js
Normal file
26
src/renderer/events/PRE_RENDER_CLEAR_EVENT.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@phaser.io>
|
||||
* @copyright 2013-2024 Phaser Studio Inc.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Pre-Render Clear Event.
|
||||
*
|
||||
* This event is dispatched by the Phaser Renderer. It happens at the start of the render step, before
|
||||
* the WebGL gl.clear function has been called. This allows you to toggle the `config.clearBeforeRender` property
|
||||
* as required, to have fine-grained control over when the canvas is cleared during rendering.
|
||||
*
|
||||
* Listen to it from within a Scene using: `this.renderer.events.on('prerenderclear', listener)`.
|
||||
*
|
||||
* It's very important to understand that this event is called _before_ the scissor and mask stacks are cleared.
|
||||
* This means you should not use this event to modify the scissor or mask. Instead, use the `prerender` event for that.
|
||||
*
|
||||
* If using the Canvas Renderer, this event is dispatched before the canvas is cleared, but after the context globalAlpha
|
||||
* and transform have been reset.
|
||||
*
|
||||
* @event Phaser.Renderer.Events#PRE_RENDER_CLEAR
|
||||
* @type {string}
|
||||
* @since 3.85.0
|
||||
*/
|
||||
module.exports = 'prerenderclear';
|
|
@ -2643,6 +2643,7 @@ var WebGLRenderer = new Class({
|
|||
* Clears the current vertex buffer and updates pipelines.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#preRender
|
||||
* @fires Phaser.Renderer.Events#PRE_RENDER_CLEAR
|
||||
* @fires Phaser.Renderer.Events#PRE_RENDER
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
@ -2655,6 +2656,8 @@ var WebGLRenderer = new Class({
|
|||
// Make sure we are bound to the main frame buffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
this.emit(Events.PRE_RENDER_CLEAR);
|
||||
|
||||
if (this.config.clearBeforeRender)
|
||||
{
|
||||
var clearColor = this.config.backgroundColor;
|
||||
|
|
Loading…
Reference in a new issue