how to change bitmap image width and height in createjs

72 Views Asked by At

I have created a game in createjs. For images I am using bitmap to load them. I am able to give them positioning in my grid. I'm trying to change its width and height but its not working.

// this is where i am loading the image. 
  buttonSolve = new createjs.Bitmap(loader.getResult("buttonCategory"));
  centerReg1(buttonSolve);
// i have tried a bunch of methods but none worked.

  // buttonSolve.setDrawSize(200, 100);
  // buttonSolve.sourceRect = { width: 280, height: 150 };
  // buttonSolve.width = buttonSize.w;
  // buttonSolve.height = buttonSize.h;
  // buttonSolve.setBounds(0, 0, 250, 400);

// this is centerReg1 function: 

function centerReg1(obj) {
  obj.regX = 195;
  obj.regY = 80;
  // obj.setBounds(0, 0, 250, 100);
  // obj.scaleX = -2;
  // obj.x = canvasW / 2 - 120;
  // obj.y = (canvasH / 100) * 75;
  // obj.sourceRect = { width: 280, height: 150 };
}

kindly someone tell me how to do this!

1

There are 1 best solutions below

2
Mandeep On

I am not 100% sure

but you can solve this issue by using scaleX & scaleY properties of
buttonSolve bitmap

buttonSolve.scaleX = newWidth / originalWidth;
buttonSolve.scaleY = newHeight / originalHeight;

2nd method

buttonSolve.setTransform(0, 0, newWidth/originalWidth, newHeight/originalHeight);

Here

  1. originalWidth & originalHeight are the original width & height
  2. newWidth & newHeight are the updated width & height