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,599
Reaction score
1,975
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,599
Reaction score
1,975
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,854
Reaction score
14,984
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

Why is there undo but not a redo like every other software in existence? :blink:
Chili: Evolved to taste spicy so no animal would eat them.

Humans: "Jokes on you ..."
I guess it becomes purely academic in less than four days but before then can anyone explain to me why the %^&*( animations in the MZ database don't have a 'Hue' slider??
Who here knows of the hidden laws of this multiverse? Such as the law of attraction
Exploding Fruits and Rasaks Pixelfarm Assets | RPG Maker News #108

Forum statistics

Threads
113,709
Messages
1,076,823
Members
147,730
Latest member
biconic
Top