MV Cutting off sprites using Javascript

Hi,

I'm currently adding a sprite with the following code:

let bitmap = ImageManager.loadBitmap("", "path/to/img"); let sprite = new Sprite(bitmap); SceneManager._scene.addChild(sprite);

I would now like to render only half of this sprite's width. How can I achieve this? Couldn't find anything useful in the documentation
Hi,

I'm currently adding a sprite with the following code:

let bitmap = ImageManager.loadBitmap("", "path/to/img"); let sprite = new Sprite(bitmap); SceneManager._scene.addChild(sprite);

I would now like to render only half of this sprite's width. How can I achieve this? Couldn't find anything useful in the documentation
Something like this would work:
JavaScript:
let bitmap = ImageManager.loadBitmap("path/to/", "img");
let sprite = new Sprite(bitmap);
sprite.setFrame(0,0, sprite.bitmap.width / 2, sprite.height);
SceneManager._scene.addChild(sprite);

Though to ensure the bitmap is loaded first you would want to use a loadListener like this:
JavaScript:
let bitmap = ImageManager.loadBitmap("path/to/", "img");
bitmap.addLoadListener(function () {
  let sprite = new Sprite(bitmap);
  sprite.setFrame(0,0, sprite.bitmap.width / 2, sprite.height);
  SceneManager._scene.addChild(sprite);
}.bind(this));
Something like this would work:
JavaScript:
let bitmap = ImageManager.loadBitmap("path/to/", "img");
let sprite = new Sprite(bitmap);
sprite.setFrame(0,0, sprite.bitmap.width / 2, sprite.height);
SceneManager._scene.addChild(sprite);

Though to ensure the bitmap is loaded first you would want to use a loadListener like this:
JavaScript:
let bitmap = ImageManager.loadBitmap("path/to/", "img");
bitmap.addLoadListener(function () {
  let sprite = new Sprite(bitmap);
  sprite.setFrame(0,0, sprite.bitmap.width / 2, sprite.height);
  SceneManager._scene.addChild(sprite);
}.bind(this));
Works like a charm, thanks!
Thank you as well for the loadListener tip.
Works like a charm, thanks!
Thank you as well for the loadListener tip.
Awesome! No Prob. Glad to help ☺️ 👍

Happy Game Making! :LZSgrin:

Original thread: https://forums.rpgmakerweb.com/threads/cutting-off-sprites-using-javascript.147479/