Skip to content

Commit 773be31

Browse files
committed
BitmapData.fastCopy test.
1 parent de07f5b commit 773be31

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

src/gameobjects/BitmapData.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ Phaser.BitmapData = function (game, key, width, height) {
132132
*/
133133
this.dirty = false;
134134

135+
this.copyCallback = null;
136+
this.copyCallbackContext = null;
137+
135138
// Aliases
136139
this.cls = this.clear;
137140

@@ -749,6 +752,67 @@ Phaser.BitmapData.prototype = {
749752

750753
},
751754

755+
756+
fastCopy: function (source, from, x, y, rotate, scaleX, scaleY, alpha, blendMode) {
757+
758+
x = x || 0;
759+
y = y || 0;
760+
rotate = rotate || 0;
761+
scaleX = scaleX || 1;
762+
scaleY = scaleY || 1;
763+
alpha = alpha || 1;
764+
blendMode = blendMode || 'source-atop';
765+
766+
// To keep this fast we're not going to do any look-ups or parameter validation
767+
768+
if (alpha <= 0)
769+
{
770+
// Because why bother wasting CPU cycles drawing something you can't see?
771+
return;
772+
}
773+
774+
var sx = 0;
775+
var sy = 0;
776+
777+
if (source instanceof Phaser.Image || source instanceof Phaser.Sprite)
778+
{
779+
sx = source.texture.frame.x;
780+
sy = source.texture.frame.y;
781+
source = source.texture.baseTexture.image;
782+
}
783+
else if (source instanceof Phaser.BitmapData)
784+
{
785+
source = source.canvas;
786+
}
787+
788+
var prevAlpha = this.context.globalAlpha;
789+
790+
this.context.save();
791+
792+
this.context.globalAlpha = alpha;
793+
794+
this.context.globalCompositeOperation = blendMode;
795+
796+
this.context.scale(scaleX, scaleY);
797+
798+
this.context.translate(x, y);
799+
800+
this.context.rotate(rotate * Math.PI / 180);
801+
802+
var w = from.width;
803+
var h = from.height;
804+
805+
// this.context.drawImage(source, sx + from.x, sy + from.y, from.width, from.height, to.x, to.y, to.width, to.height);
806+
this.context.drawImage(source, sx + from.x, sy + from.y, w, h, -from.width/2, -from.height/2, w, h);
807+
808+
this.context.restore();
809+
810+
this.context.globalAlpha = prevAlpha;
811+
812+
this.dirty = true;
813+
814+
},
815+
752816
/**
753817
* Copies the pixels from the source image to this BitmapData based on the given area and destination.
754818
*
@@ -760,6 +824,8 @@ Phaser.BitmapData.prototype = {
760824
* @param {object} [transform] - A transform object containing the properties scaleX, scaleY, skewX, skewY, translateX and translateY.
761825
* @param {string} [blendMode] - ?
762826
*/
827+
828+
763829
blit: function (image, source, dest, alpha, transform, blendMode) {
764830

765831
var setAlpha = false;

0 commit comments

Comments
 (0)