ecj2 / momo

[NOT MAINTAINED / ABANDONED] A simple 2D game-making library written in JavaScript.
MIT License
1 stars 0 forks source link

Clipped texture drawn upside-down #39

Closed ecj2 closed 4 years ago

ecj2 commented 4 years ago

When creating a new texture, drawing into said texture, then drawing a clipped version of that texture to the screen, the clipped texture is upside-down.

async function main() {

  Momo.initialize("example", 768, 432);

  let example_texture = await Momo.loadTexture("example.png");

  Momo.clearToColor(Momo.makeColor(1, 1, 1));

  let w = Momo.getTextureWidth(example_texture);
  let h = Momo.getTextureHeight(example_texture);

  Momo.drawTexture(example_texture, 0, 0);
  Momo.drawClippedTexture(example_texture, w / 2, h / 2, w / 2, h / 2, 0, h);

  let new_texture = Momo.createTexture(w, h);
  Momo.setTargetTexture(new_texture);
  Momo.drawTexture(example_texture, 0, 0);
  Momo.setTargetTexture(Momo.getDefaultTexture());

  Momo.drawTexture(new_texture, w * 2, 0);
  Momo.drawClippedTexture(new_texture, w / 2, h / 2, w / 2, h / 2, w * 2, h);
}

Momo.setEntryPoint(main);

From the above, when drawing example_texture normally and clipped, the texture appears right-side up, as expected. Likewise, when normally drawing new_texture, it is also right-side up. However, when drawing a clipped version of new_texture, it is upside-down.