How to Display an Image in a Window

abreyer3

Villager
Member
Joined
Oct 26, 2015
Messages
12
Reaction score
1
First Language
English
I've been searching, but I've had no luck in finding javascript code that would work. I want to display a png image in a window from the pictures folder, but any code I find either spits out an error or doesn't work at all. Would someone be able to write a code template I can use? Thanks for your time.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,338
Reaction score
3,019
First Language
Portuguese
Primarily Uses
RMMV
Code:
  Window_Base.prototype.drawPicture = function(filename, x, y) {    var bitmap = ImageManager.loadPicture(filename);    this.contents.blt(bitmap, 0, 0, bitmap._canvas.width, bitmap._canvas.height, x, y);  };
 

abreyer3

Villager
Member
Joined
Oct 26, 2015
Messages
12
Reaction score
1
First Language
English
Okay, thanks for the template. So for testing purposes, I put it so that the 'Loading.png' picture will display in the gold window, but it is still not displaying the image. I call the function when the gold window is called. What am I doing wrong? I get no errors, and the debug console isn't saying anything. I also don't have any plugins enabled. Sorry if this is a really simple solution I can't see, I'm trying to learn Javascript.

Screenshots are of the code in question and how it appears in the game:

Screenshot_1.png

Screenshot_2.png
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,338
Reaction score
3,019
First Language
Portuguese
Primarily Uses
RMMV
You're drawing the picture on the initialize method, this means the picture will be drawn once and never again. Then you immediatelly call the refresh method, that erases everything that is drawn to draw again.


You need your drawPicture to be called from inside that refresh method (after the line that says this.contents.clear ).
 

abreyer3

Villager
Member
Joined
Oct 26, 2015
Messages
12
Reaction score
1
First Language
English
You're drawing the picture on the initialize method, this means the picture will be drawn once and never again. Then you immediatelly call the refresh method, that erases everything that is drawn to draw again.

You need your drawPicture to be called from inside that refresh method (after the line that says this.contents.clear ).
Thank you! Thank you! It works! I knew it was some easy solution I overlooked, but now I understand. Thanks again! :D
 

ArkDG

Veteran
Veteran
Joined
May 26, 2013
Messages
143
Reaction score
46
First Language
portuguese
Primarily Uses
How do I resize the picture?

I have a picture that is too big, but I want to reduce its size to put in the window without having to modify the original file. :/
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
856
First Language
German
Primarily Uses
Bitmap.blt() has 2 optional parameters:

this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y, (dw), (dh));"dw" and "dh" signalize how big the drawn image should be and default to the default values (in this case bitmap.width and bitmap.height).
 

ValiLey

Warper
Member
Joined
May 2, 2017
Messages
4
Reaction score
0
First Language
German
Primarily Uses
RMMV
Hi there,

I'm also trying to display an image in a window and I used Hudell's DrawImage function, but even though I don't get an error, no image is drawn.
The function call is inside the refresh method and the image is in the picture folder.
I've checked this over and over again, but I can't find any reason, why the image would not be drawn - maybe I'm turning blind...

Would someone please double-check the code for me?

window.PNG
 

neition

Warper
Member
Joined
Oct 30, 2015
Messages
2
Reaction score
0
First Language
korean
Primarily Uses
when... anyone have problem like me.
if you display sprite(picture ,face, svenemise any one) under window.
let's do like that.

var bitmap = new Sprite(ImageManager.loadPicture(temp_file_name));
this.addChildToBack(bitmap);//it very important. it same add child, but your sprite display under window simply
bitmap.setFrame(0,0,this.width,this.height);
 

dbchest

Beast Master
Veteran
Joined
Oct 1, 2013
Messages
434
Reaction score
299
First Language
English
Primarily Uses
RMMV
why use bitmap._canvas.width and bitmap._canvas.height? try bitmap.width and bitmap.height.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Been parallax mapping nigh all night. :D
2nd character based on the same random inputs
the coffee shop i go to for open mic every friday only has 2 more open mics left and then they're done :'( i'm gonna die!
Everytime someone says Intel "kabylake" I hear either baby lake or ladycake.
Either I just had one of those dreams where you think you're awake, or I have time traveled. I woke up at 6:58am this morning, heard my father leaving for work, laid back down, now its 1:16am.

Forum statistics

Threads
93,383
Messages
911,873
Members
122,885
Latest member
Hayato7729
Top