Looking for function copyPixels

I created a project a decade ago. I am now updating to Phaser 3 and plan on adding new features. :smiley: In Phaser 2.0.5 there was a function called copyPixels. I am trying to find out if this got removed or replaced with another function. This was the function
copyPixels: function (a, b, c, d) {
“string” == typeof a && (a = this.game.cache.getImage(a)),
a && this.context.drawImage(a, b.x, b.y, b.width, b.height, c, d, b.width, b.height),
(this.dirty = !0);
},

Thanks

There isn’t a Phaser 3 method exactly like the Phaser 2 copyPixels(). A replacement would be something like

Phaser.Textures.CanvasTexture.prototype.copyPixels = function(
  source, 
  sourceRect, 
  destX, 
  destY
) {
  if (typeof source === 'string') {
    source = this.manager.get(source);
  }

  this.context.drawImage(
    source,
    sourceRect.x,
    sourceRect.y,
    sourceRect.width,
    sourceRect.height,
    destX,
    destY,
    sourceRect.width,
    sourceRect.height
  );

  this.update();

  return this;
}

If you don’t need a source rectangle then you could use drawFrame().

1 Like

Thanks. I did figure this out before the post was allowed to be posted, as it was my first post. I found out a lot has changed and I am making those changes.