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
403
Reaction score
66
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

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,748
Reaction score
2,100
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
403
Reaction score
66
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

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,748
Reaction score
2,100
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
43,347
Reaction score
15,158
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 Profile Posts

Too bad the Boss Battle Build Bout isn't also for VXAce.
I might not participate in the Boss Battle contest after all... I have more important things to do, like Wishful Wanda. And of course the Dark Deception spinoff I plan to pitch, Demon Slayer.
Changed my avatar, goodbye Alan Sugar, hello George Carlin (one of my favorite human beings ever)
If you still don't subscribe our Polish channel please consider it :)
1.png
Who wants to see my review of the worst star wars movie? This movie has all the excitement of being on Jury Duty of the most boring case ever about trade negotiations.

Forum statistics

Threads
115,171
Messages
1,087,814
Members
149,724
Latest member
scurvyDan
Top