RMMV Getting picture's width and height via Script Call \ Check if Mouse touches a Picture

Status
Not open for further replies.

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
357
Reaction score
51
First Language
Spanish
Primarily Uses
RMMV
Is it possible? I've found a few threads but none of them worked, unfortunately. I've also tried QPicture plugin, the rest of them are not free for commercial use.
Here are some script calls I've tried using:
Code:
SceneManager._scene._spriteset._pictureContainer.children[pictureId - 1].width

const picId = 5;
SceneManager._scene._spriteset._pictureContainer.children[picId - 1]?.isBeingTouched()

ImageManager.loadPicture($gameScreen.picture(1).name("anna2")).height

I've tried both settings and then checking variables' values and a simple conditional branch with the second script.
Any thoughts?

UPD. I have also checked the PictureCallCommon plugin. And yet, nothing
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,596
Reaction score
1,969
First Language
EN
Primarily Uses
RMMZ
This sort of thing seems to work for me (picture ID 1):
JavaScript:
SceneManager._scene._spriteset._pictureContainer.children[0].width
RMMV loads file data asynchronously. If you want to show a picture then immediately check its bitmap properties, I suggest attaching your code as a load listener, e.g.
JavaScript:
ImageManager.loadPicture('anna2').addLoadListener(function() {
  console.log(this.height);
});
The load listener will run once the picture has loaded (and, if necessary, been decrypted). Note that this applies to the raw bitmap; the sprite might have scaling or other transformations applied. For more technical details, check out rpg_core.js~

To check if the cursor is over a picture, you can compare TouchInput.x and TouchInput.y with the picture's x, y, width, and height. The RMMZ core scripts have shortcuts for this stuff, e.g. Sprite_Picture#isBeingTouched, but RMMV does not.

Also, note that the name method of Game_Picture does not expect any arguments. It simply gets the file name associated with that picture.
 

KotoYama

Veteran
Veteran
Joined
Apr 20, 2019
Messages
357
Reaction score
51
First Language
Spanish
Primarily Uses
RMMV
So, I've tried this, but it didn't work
◆Mostrar imagen:#1, anna2, Superior izquierda (0,0), (50%,50%), 255, Normal
◆Script:ImageManager.loadPicture('anna2').addLoadListener(function() {
: : console.log(this.height);
: :});
◆Control de variables:#0019 SelfVar Visualizer = SceneManager._scene._spriteset._pictureContainer.children[0].width
◆Control de variables:#0019 SelfVar Visualizer = SceneManager._scene._spriteset._pictureContainer.children[0].width
◆Esperar:15 fotogramas
◆Mensaje:Nada, Ventana, Inferior
: :\V[19]

But I've added a little waiting command and changed the order of plugin commands so now QPicture works perfectly fine!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,596
Reaction score
1,969
First Language
EN
Primarily Uses
RMMZ
Good to hear you got it working! Happy RPG Making~ :kaojoy:

For what I suggested to work, you'd need to replace the console.log(this.height) part with whatever you want to happen when the image loads, e.g. $gameVariables.setValue(19, this.width).

After seeing the full situation, though, it looks like you want to pause the event interpreter until the image is loaded. In that case, this Script command is probably a better option:
JavaScript:
ImageManager.requestPicture('anna2');
this.setWaitMode('image');
I think that will initialise a cache key for that image and tell the interpreter to wait until it's done loading. reservePicture may be better if you're going to be referencing this particular image a lot.

No need to try other things if what you've got now is working, though! :kaohi:
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,827
Reaction score
14,980
First Language
English
Primarily Uses
RMMV

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I don't believe it. I actually did some proofreading in my game - and fixed some grammar errors! I feel so accomplished, knowing I can actually proofread my own writing!
...I've had a bad day, okay? Bad enough for me to want to proofread stuff. :yswt2:
Ughhh, July is not my month. Thankfully, it's nearly done.

I fixed the lips and noses for MZ! The files have been updated.
qQwgk8C.png

Everything below!
Ugh, I opened MV after a few weeks and I'm completely lost on what I was working on.
Does it happen to someone else or am I the only disorganized one around? :kaoswt:
xH5Fk2f.jpg
Today was not a really productive day, but at least i got some bust sketches going <3
E7QXZHNXoAIkpG8
hmm in exploring MZ with FOSSIL... I see I'll probably need to stick with MV for now as none of the menu altering plugins I use work on MZ lol. and I don't have the money to dump into what I would need in some cases to update plugins to their MZ versions. Everytime I think of converting, 5 or more reasons popup on why I shouldn't.

Forum statistics

Threads
113,665
Messages
1,076,530
Members
147,685
Latest member
SoulandSpirit
Top