Jump to content

How to show several parts from BitmapData


NokFrt
 Share

Recommended Posts

I have a BitmapData object. This object is used as a texture for several Images (Phaser.Image). Every image is on a different position in the world and every image should show only a specified part of the BitmapData. I thought I can achieve that by settings a different cropRect for each image, but that doesn't work. If I do this:

img1.cropRect.set(0, 0, 100, 100);
img1.updateCrop();

img2.cropRect.set(200, 0, 100, 100);
img2.updateCrop();

then the img1 shows exactly the same thing as the img2 and completely ignores its own cropRect.

The BitmapData object is dynamically updated every step so I can't generate different texture for each image.

I also tried using frames but the results is still the same:

let frame1 = new Phaser.Frame(0, 0, 0, 100, 100, "topLeft");
let frame2 = new Phaser.Frame(1, 100, 0, 100, 100, "topRight");

bmd.frameData.addFrame(frame1);
bmd.frameData.addFrame(frame1);

img1.setFrame(frame1);
img2.setFrame(frame2);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...