MV Placing HTML image element on top of the GameCanvas?(SOLVED)

Hi, been trying to place an image on top of the GameCanvas in order to utilize the style image-rendering: pixelated.

However, the image-element always goes underneath the GameCanvas. See image:
1633795595784.png


z-index doesn't matter, and element placement within the body doesn't matter either.

And since I am adding the element with javascript and gonna be editing the element with javascript, that's why I'm posting here. I think it should be relevant 😛

Other solution would be to draw the image directly on the canvas, but I've had no luck with this. It just says that context.drawImage() is not a function. Which is rather strange, but okay.

And yet another solution would be if I could change the scaling function of pictures to be nearest neighbor rather than the blurry messes it produces at the moment.

Any response and/or help on this would be greatly appreciated! 🙂

Edit:
Decided to make the base image larger rather than small and then shrink it rather than sizing it up. Should fix the blur. The topic is still interesting to figure out though as I've often wondered about this.
I tried that by myself with a normal homepage containing a canvas and that did not work either.

But it did work if i put that property on a canvas itself.

So i assume, that the property affects only canvas elements within the element and not all that lies beneath.
Hello!

However, the image-element always goes underneath the GameCanvas
Without seeing your code it's impossible to know where you're going wrong.

By my test you probably forgot to set the "position" in CSS.

I did it like this, include it with CSS directly in the HTML:
CSS:
img {
  position: absolute;
  left: 0px;
  top: 0px;
  z-index: 10;
  image-rendering: crisp-edges;
}
(I put 10 because all the zIndex I found in the code use 1 to 9)

And inside BODY I inserted the image (50% in relation to page size):
HTML:
<img src="icon/icon.png" width="50%" />

Decided to make the base image larger rather than small and then shrink it rather than sizing it up. Should fix the blur. The topic is still interesting to figure out though as I've often wondered about this.
Instead of pixelated, I used crisp-edges, but in my case both had the same effect in this case.

Here's a question about it:

RMMV Index.html Source:
Spoiler
HTML:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <meta name="viewport" content="user-scalable=no">
        <link rel="icon" href="icon/icon.png" type="image/png">
        <link rel="apple-touch-icon" href="icon/icon.png">
        <link rel="stylesheet" type="text/css" href="fonts/gamefont.css">
        <style>
        img {
          position: absolute;
          left: 0px;
          top: 0px;
          z-index: 10;
          image-rendering: crisp-edges;
        }
        </style>
        <title>Secret Pass</title>
    </head>
    <body style="background-color: black">
        <script type="text/javascript" src="js/libs/pixi.js"></script>
        <script type="text/javascript" src="js/libs/fpsmeter.js"></script>
        <script type="text/javascript" src="js/libs/lz-string.js"></script>   
        <script type="text/javascript" src="js/main.js"></script>
        <img src="icon/icon.png" width="50%" />
    </body>
</html>

Good luck!
RMMV's Bitmap wrapper (rpg_core.js) determines its scale mode based on its smooth flag.
  • Smooth bitmaps use linear scaling, non-smooth use nearest-neighbour.
  • This flag is generally set when the bitmap loads (see ImageManager.loadBitmap in rpg_managers.js).
  • By default:
    • High-res images (pictures, parallax, etc) are smooth;
    • Low-res images (tilesets, map characters, etc) are not smooth.
To use nearest-neighbour scaling for all images, you could try this as a plugin:
JavaScript:
(function(alias) {
  ImageManager.loadBitmap = function(folder, filename, hue, smooth) {
    // Call original method with smooth = false
    alias.call(this, folder, filename, hue, false);
  };
})(ImageManager.loadBitmap);
Hello!


Without seeing your code it's impossible to know where you're going wrong.

By my test you probably forgot to set the "position" in CSS.

I did it like this, include it with CSS directly in the HTML:
CSS:
img {
  position: absolute;
  left: 0px;
  top: 0px;
  z-index: 10;
  image-rendering: crisp-edges;
}
(I put 10 because all the zIndex I found in the code use 1 to 9)

And inside BODY I inserted the image (50% in relation to page size):
HTML:
<img src="icon/icon.png" width="50%" />


Instead of pixelated, I used crisp-edges, but in my case both had the same effect in this case.

Here's a question about it:

RMMV Index.html Source:
Spoiler
HTML:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <meta name="viewport" content="user-scalable=no">
        <link rel="icon" href="icon/icon.png" type="image/png">
        <link rel="apple-touch-icon" href="icon/icon.png">
        <link rel="stylesheet" type="text/css" href="fonts/gamefont.css">
        <style>
        img {
          position: absolute;
          left: 0px;
          top: 0px;
          z-index: 10;
          image-rendering: crisp-edges;
        }
        </style>
        <title>Secret Pass</title>
    </head>
    <body style="background-color: black">
        <script type="text/javascript" src="js/libs/pixi.js"></script>
        <script type="text/javascript" src="js/libs/fpsmeter.js"></script>
        <script type="text/javascript" src="js/libs/lz-string.js"></script>  
        <script type="text/javascript" src="js/main.js"></script>
        <img src="icon/icon.png" width="50%" />
    </body>
</html>

Good luck!
I did forget the code, but that is what I did as well. The picture I attached does show the CSS and that it is set to absolute for position.

The code I used:
timeBG = document.createElement('img'); timeBG.src = "img/pictures/TimeKeeper.png"; document.body.appendChild(timeBG);

And again, I did not set any style within the script as of yet I was changing it within the element editor of the node.js. Works perfectly fine, code yields the same result.

Worth noting is that I tried changing it to prepend instead of append just in case. I also moved the element around within the element editor.

I looked at the z-index for the other canvases and just set it to the one above. There is no limit, reasonably, for how high the z-index can go, I think I tried setting it to 5, 8, 100, and then to 4837(or so).

RMMV's Bitmap wrapper (rpg_core.js) determines its scale mode based on its smooth flag.
  • Smooth bitmaps use linear scaling, non-smooth use nearest-neighbour.
  • This flag is generally set when the bitmap loads (see ImageManager.loadBitmap in rpg_managers.js).
  • By default:
    • High-res images (pictures, parallax, etc) are smooth;
    • Low-res images (tilesets, map characters, etc) are not smooth.
To use nearest-neighbour scaling for all images, you could try this as a plugin:
JavaScript:
(function(alias) {
  ImageManager.loadBitmap = function(folder, filename, hue, smooth) {
    // Call original method with smooth = false
    alias.call(this, folder, filename, hue, false);
  };
})(ImageManager.loadBitmap);
This looks rather interesting. All I found regarding at first was this post, which didn't seem all that promising tbh.

I guess since the question is about bi-linear it makes quite the difference I suppose.

Is that applied to the animated battlers as well? When you go bigger resolution the objects in the battle screen don't scale. No surprise there, but how would I go about scaling them up?
1633806103209.png


Supposed to be three times bigger, at least. It would depend on the active resolution.

Best regards,
Changing the size of the display area (i.e. resolution) and scaling the current screen to fit the available space are two different things.

Animated sideview actors use the non-smooth scale mode (i.e. nearest-neighbour) by default. You can check each image type in rpg_managers.js, e.g. ImageManager.loadSvActor.

RMMV's Sprite wrapper offers a scale property that can be used to adjust sizes on the fly, e.g.
JavaScript:
(function(alias) {
  Sprite_Actor.prototype.initialize = function() {
    alias.apply(this, arguments);
    // Set both x- and y-scales to 3 = 300%
    this.scale.x = 3;
    this.scale.y = 3;
  };
})(Sprite_Actor.prototype.initialize);

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/placing-html-image-element-on-top-of-the-gamecanvas-solved.141135/