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,779
Reaction score
4,724
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,779
Reaction score
4,724
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,020
Reaction score
5,332
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

2021? I still wonder if people still doing MV than MZ more
Seeing a lot more active Ace topics recently, is it making a comeback? :o
0-7, left-to-right, top-to-bottom
As soon as I'm able to get out of bed I'm probably gonna go so hyper from being too cooped up, and burn myself out into another awful flare. lol
It makes me feel proud whenever an RM game does well. Even though I had nothing to do with it.

Forum statistics

Threads
107,627
Messages
1,031,013
Members
139,746
Latest member
Krunga
Top