Problems getting bitmap.width and bitmap.height

Status
Not open for further replies.

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi people!
I was making a plugin that creates a bitmap on the screen.
But I'm having some problems getting the width and height of that.

I have a function that receives arguments that help put the bitmap in a predefined position on the screen through his width and height.
when I create the bitmap, it does not give me his width and height, in the function "setPosition"

JavaScript:
Sprite_PressStart.prototype.initialize = function() {
    Sprite_Base.prototype.initialize.call(this);
    this.createBitmap();
    this.setPositions();
};

Sprite_PressStart.prototype.createBitmap = function(){
    const image = ImageManager.loadSystem(Eli.PressStart.Param.image);
    this.bitmap = image;
    console.log(this.bitmap.width) // returns 0
    console.log(this.bitmap.height) // returns 0
   
};
   
Sprite_PressStart.prototype.setPositions = function(){
    const param = Eli.PressStart.Param;
    const position = Eli.Book.presetPos(this.bitmap.width, this.bitmap.height, param.customX, param.customY, param.preset);
    this.move(position.x, position.y);
};

Sprite_PressStart.prototype.update = function(){
    //this.setPositions(); If I put it here, everything works fine and I can get the sizes of the bitmap.
    // More code here...
};
But if I put the function "setPosition" to be called on the update, it will give me the width and height, but only after the first update. Because in the first, it will always give me 0 for both sizes.

This sprite is created in Scene_Title. Perhaps I should set the X and Y position on the function from the Scene_Title that I'm using to create the sprite?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Issue is related to async loading.
When you make a request to load an image, the game will go and load the file for you but it might not be ready when you access it.

You would either have to do some sort of callback when it's ready, or just rely on that update code to check if it's loaded or not.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
@Tsukihime
Oh, thanks for that!
I have reserved the system image previously and now it works fine!
JavaScript:
ImageManager.reserveSystem
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
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.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top