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
358
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,606
Reaction score
1,988
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
358
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,606
Reaction score
1,988
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,860
Reaction score
14,989
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

Here's this for an idea I might do: A Touhou RPG set in the universe of the Hoi4 mod "The New Order: Last Days of Europe". Expect BurgSys Yukari, the Great Fairy Trial, and funni clock Flandre
The thing I don't like about VRMMORPG anime is that they're unrealistic. I mean, we know we have a lot of ping issues, latency, and desync. Would be funny if you shoot a player and they immediately teleport somewhere because "ha, your internet suck!".
I've decided to try and be more social and less nervous about engaging. I'm always over thinking things - from now on when I'm worried or don't get something I'll just ask.
Sometimes a mechanic that is meant to add challenge is just annoying. Even the Final Fantasy games did not completely escape this pitfall of design. (FF8 draw system I'm looking at you - grrrr)
starting working on the sprites for one of my games major antagonists finally. here's the first frame of his chanting motion in battle.

Forum statistics

Threads
113,748
Messages
1,077,157
Members
147,777
Latest member
jojoboivin
Top