RMMZ How to get the width and height of a image.

Status
Not open for further replies.

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
498
Reaction score
227
First Language
English
Primarily Uses
RMMZ
Basically I want to do this...

Variable BustX = Graphics.width - picture.width
Variable BustY = Graphics.height - (picture.height + y offset from bottom (136))

Problem is how do I get the size of an image? (picture)
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,822
Reaction score
4,754
First Language
English
Primarily Uses
RMMZ

I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.


Like this:
Code:
sprite.width // gets the width of the image
sprite.height // gets the height of the image
The problem is that if you call this right after the sprite is created, you will get nothing since the image hasn't been loaded yet. So you either have to wait a couple frames, or find a work around. I personally added this in the update method:
Code:
Sprite_Thing.prototype.update = function() {
    Sprite_Base.prototype.update.call(this);
    if (this.width && this.height) {
        @canGetWidthHeight = true
    }
}

Sprite_Thing.prototype.getWidth = function() {
    if (@canGetWidthHeight) return this.width;
}

EDIT: This is what I did in MV and have not tried in MZ yet. I'm assuming it's also working in MZ, and I'm also assuming the loading delay is still there.
 

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
498
Reaction score
227
First Language
English
Primarily Uses
RMMZ
Okay let me reiterate my question. How do get I get sprite.width sprite.height of a specific picture.

$gameScreen.picture(1).width and $gameScreen.picture(1).height do not work btw even after waiting 4 frames.
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,822
Reaction score
4,754
First Language
English
Primarily Uses
RMMZ
Ahh, then it's much trickier. Game_Picture isn't a sprite so it doesn't have the width and height property. That means you need to either get it in the Sprite_Picture object (meaning you'll have to play inside the Spriteset_Map), or you modify the Game_Picture object so that it keeps the width and height data. I never play around with Game_Picture, so perhaps there's an easier way that I'm not aware of.
 

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
498
Reaction score
227
First Language
English
Primarily Uses
RMMZ
Okay now I know something is screwy. I just checked. And it is infact a sprite. or at least should be.
:ewat:

Tried adding this bit of code. Too no effect.

Code:
/*:
@target MZ
@plugindesc Allows you to grab the width and height of pictures.
@author Nekohime
*/
(() => {


    // Setting pluging name
    const pluginName = 'Neko_PictureFix';

    //add width and height to pictures. -_-
    Game_Picture.prototype.width = function() {
        return this._width;
    };

    Game_Picture.prototype.height = function() {
        return this._height;
    };

})();
 
Last edited:

Krimer

Veteran
Veteran
Joined
May 10, 2013
Messages
150
Reaction score
114
First Language
Ukrainian
You can do some ugly direct calls to sprites if its what you want
Code:
var picSpriteset = SceneManager._scene._spriteset.children.find(obj => obj.children.length >= 99);
picSpriteset.children[0].width
picSpriteset.children[0].height
children[0] - is your picture IDs from 0 to 99
 

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
498
Reaction score
227
First Language
English
Primarily Uses
RMMZ
You sir are a godsend.
It's an ugly hack. But it works and that's all that matters.
Thanks Krimer.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,135
Reaction score
5,373
First Language
Dutch
Primarily Uses
RMXP

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

Today is the day! I will be productive in game dev work! I will - *gets distracted by cat playing with her toy mouse* Awww <3
Whelp. I tried to be productive.
Decided to work on Fandom Scouts today. I've decided that instead of using the generic "scrolling text" event that MV has (I'm using MV for FS, not MZ) I'll use the movie option. I'm still trying to find a way to get Premiere Pro to output the compatible format though. If anyone can give me some help, it would be greatly appreciated!
Barthdry wrote on tln143's profile.
Hello tln143 Welcome to the RPG Maker Forum. We wish you enjoy and make good rpg games
Barthdry wrote on 00cassiesmells's profile.
Hello 00casiemells Welcome to the RPG Maker Forum. We wish you enjoy and make good rpg games
Remember guys: Drink water and workout is important too! Don't stay too much time on the PC working! :D

Forum statistics

Threads
109,034
Messages
1,041,498
Members
141,520
Latest member
GabeUrBoi
Top