Skip to content

Commit 5ad3698

Browse files
committed
BitmapData.clear has 4 new optional parameters: x, y, width and height, that define the area to be cleared. If left undefined it works exactly the same as before and clears the entire canvas.
1 parent 0dc8757 commit 5ad3698

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ Version 2.4 - "Katar" - in dev
379379
* Debug.currentAlpha wasn't being used to set the alpha of the Debug context at all (was always set to 1) but now updates the alpha of the Debug context before anything is rendered to it (thanks @wayfu #1888)
380380
* If the device is detected as a Windows Phone the renderer is automatically set to use Canvas, even if WebGL or AUTO was requested (thanks @ramarro123 #1706)
381381
* RandomDataGenerator.weightedPick has been tweaked slightly to allow for a more even distribution of weights. It still favors the earlier array elements, but will accurately include 'distance' elements as well (thanks @gingerbeardman #1751)
382+
* BitmapData.clear has 4 new optional parameters: x, y, width and height, that define the area to be cleared. If left undefined it works exactly the same as before and clears the entire canvas.
382383

383384
### Bug Fixes
384385

src/gameobjects/BitmapData.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,24 @@ Phaser.BitmapData.prototype = {
416416
/**
417417
* Clears the BitmapData context using a clearRect.
418418
*
419+
* You can optionally define the area to clear.
420+
* If the arguments are left empty it will clear the entire canvas.
421+
*
419422
* @method Phaser.BitmapData#clear
423+
* @param {number} [x=0] - The x coordinate of the top-left of the area to clear.
424+
* @param {number} [y=0] - The y coordinate of the top-left of the area to clear.
425+
* @param {number} [width] - The width of the area to clear. If undefined it will use BitmapData.width.
426+
* @param {number} [height] - The height of the area to clear. If undefined it will use BitmapData.height.
420427
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
421428
*/
422-
clear: function () {
429+
clear: function (x, y, width, height) {
430+
431+
if (typeof x === 'undefined') { x = 0; }
432+
if (typeof y === 'undefined') { y = 0; }
433+
if (typeof width === 'undefined') { width = this.width; }
434+
if (typeof height === 'undefined') { height = this.height; }
423435

424-
this.context.clearRect(0, 0, this.width, this.height);
436+
this.context.clearRect(x, y, width, height);
425437

426438
this.dirty = true;
427439

typescript/phaser.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="pixi.d.ts" />
22
/// <reference path="p2.d.ts" />
33

4-
// Type definitions for Phaser 2.4.0 2015-Jul-08
4+
// Type definitions for Phaser 2.4.0 2015-Jul-09
55
// Project: https://github.com/photonstorm/phaser
66

77
declare class Phaser {
@@ -244,7 +244,7 @@ declare module Phaser {
244244
blendSourceOver(): Phaser.BitmapData;
245245
blendXor(): Phaser.BitmapData;
246246
circle(x: number, y: number, radius: number, fillStyle?: string): Phaser.BitmapData;
247-
clear(): Phaser.BitmapData;
247+
clear(x?: number, y?: number, width?: number, height?: number): Phaser.BitmapData;
248248
cls(): Phaser.BitmapData;
249249
copy(source?: any, x?: number, y?: number, width?: number, height?: number, tx?: number, ty?: number, newWidth?: number, newHeight?: number, rotate?: number, anchorX?: number, anchorY?: number, scaleX?: number, scaleY?: number, alpha?: number, blendMode?: number, roundPx?: boolean): Phaser.BitmapData;
250250
copyPixels(source: any, area: Phaser.Rectangle, x: number, y: number, alpha?: number): void;

0 commit comments

Comments
 (0)