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
411
Reaction score
67
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,764
Reaction score
2,111
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
411
Reaction score
67
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,764
Reaction score
2,111
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,372
Reaction score
15,183
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

Should've done this a few days ago but...
PRI_200136808.jpg
Rest in Peace, Sir Clive Sinclair
1940 - 2021
Entrepreneur, Technologist, Father of the British Computing Industry, and protagonist of Legend of ZUN.

Without you, England's games and tech industry wouldn't be where it is.
Woof, haven't touched any game-making elements in a couple of weeks I think.
Doing a thing in MV...

R3PuRjF.png
Don't you just hate it when you get a high level armor only for it to look like a metal plated bikini on your female character?? Seriously. How can that protect you??? Enemies can hit the squishy parts! :kaosigh:

Forum statistics

Threads
115,284
Messages
1,088,622
Members
149,904
Latest member
Martine1979
Top