[SOLVED] How do I "draw" a white square on the screen?

Status
Not open for further replies.

Cheesy

Villager
Member
Joined
Nov 13, 2018
Messages
5
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
This is probably a super easy problem to solve, but I'm still a newbie at js so I don't know what to do.

I need a map event to make a sprite appear on the screen with a script call, like you would with a picture, but I'm not using those because for what I've seen they are not as dynamic and there is a limit to how many you can have on screen at the same time. I want to learn how to use sprites so I can try making HUD's and "bone" animations independent of the current scene.

One of the codes I tried was from this thread. I changed the scene from title to map to test it, so it looked exactly like this inside the script call:

Code:
var aliasCreate = Scene_Map.prototype.create;
Scene_Map.prototype.create = function() {
aliasCreate.call(this);
var bitmap = new Bitmap(20, 20);
bitmap.fillAll('white');
var sprite = new Sprite(bitmap);
this._whiteSquare = sprite;
this.addChild(sprite);
};
but nothing appeared. I tried adding positions after this.addChild(sprite); with

Code:
this.sprite.x = 0;
this.sprite.y = 0;
this.sprite.z = 2;
but still, nothing appeared on screen.

Sorry if this is simple, I have difficulty learning stuff on my own and can't keep track of everything happening in the js files. So if anyone could send me the exact code I need to use just to show this white square it would be very appriciated.

EDIT:
The kind Mr. Poryg provided the correct code for my case!

Code:
var bitmap = new Bitmap(20, 20);
bitmap.fillAll('white');
var sprite = new Sprite(bitmap);
this._whiteSquare = sprite;
SceneManager._scene.addChild(sprite);
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,063
Reaction score
10,364
First Language
Czech
Primarily Uses
RMMV
When the bitmap has no texture, no wonder it doesn't look like anything.
Edit: Nevermind, overlooked one line of code.
 

Cheesy

Villager
Member
Joined
Nov 13, 2018
Messages
5
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
When the bitmap has no texture, no wonder it doesn't look like anything.
Edit: Nevermind, overlooked one line of code.
But I also don't know how to set textures, so any explanation on that would be appriciated as well.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,063
Reaction score
10,364
First Language
Czech
Primarily Uses
RMMV
I see where the problem is now. You're using it on the create method, which is too soon. Use it on the createDisplayObjects method instead.
The rest of your code is correct. I just overlooked one line of it yesterday, so I thought it wasn't.
 
Last edited:

Cheesy

Villager
Member
Joined
Nov 13, 2018
Messages
5
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
I see where the problem is now. You're using it on the create method, which is too soon. Use it on the createDisplayObjects method instead.
The rest of your code is correct. I just overlooked one line of it yesterday, so I thought it wasn't.
Well I assume you meant for me to change Scene_Map.prototype.create to Scene_Map.prototype.createDisplayObjects, so now the code looks like this but still nothing
Code:
var aliasCreate = Scene_Map.prototype.createDisplayObjects;
Scene_Map.prototype.createDisplayObjects = function() {
aliasCreate.call(this);
var bitmap = new Bitmap(20, 20);
bitmap.fillAll('white');
var sprite = new Sprite(bitmap);
this._whiteSquare = sprite;
this.addChild(sprite);
this.sprite.x = 408;
this.sprite.y = 312;
this.sprite.z = 2;
};
(changed coordinates to see if it wasn't hidding in the corner)

I also tried replacing Scene_Map.prototype.create entirely by createDisplayObjects instead, but that returned an error saying it was not defined. And nothing happened by trying Scene_Map.createDisplayObjects either.

Sorry, I just really don't know anything about how these methods should work.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,063
Reaction score
10,364
First Language
Czech
Primarily Uses
RMMV
In that case open the game console (press f8 while playtesting) and copy
Code:
var bitmap = new Bitmap(20, 20);
bitmap.fillAll('white');
var sprite = new Sprite(bitmap);
this._whiteSquare = sprite;
SceneManager._scene.addChild(sprite);
Does it work?
 

Cheesy

Villager
Member
Joined
Nov 13, 2018
Messages
5
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
OH MY GOD THERE IT IS! IT EVEN WORKS IN THE MAP EVENT! (I knew about the console log, but didn't think I could paste and run code in it!)

Thank you so much Sir, I cracked my head with this for a while now, I'm very grateful!

Although I can't figure out how to make it show a picture from the files instead, this is fine for now, it's already a big step for me. Should I make another thread for that some other time? Thanks again!
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,063
Reaction score
10,364
First Language
Czech
Primarily Uses
RMMV
Yeah, according to forum rules you should make another thread for it.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,496
Reaction score
4,405
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

I discovered the new English word "Secular religion" today It is an oxymoron word. Now, I wonder how many English words create per year? According to Global Language Monitor, around 5,400 new words are created every year; it's only the 1,000 or so deemed to be sufficiently widespread use that makes it into print. [I think it probably slangs or combines words] :kaoluv:
Is it normal that I love a game that I can't even play due to how bad I'm at it?
Anyone have advice for recruiting friends to bugtest with you? I had some buddies volunteer without me asking, and we agreed on dates and times... and they all just flaked...
A mousefolk sprite I made, I think I did good.
Discovering math. functions for damage formulas was one of the greatest things for me.
It's very useful for balancing skills to work in a variety of possible circumstances.
For example if you have a skill that is supposed to work for both mages and warriors:
Code:
Math.max(a.atk * 2 - b.def, a.mat * 2 - b.mdf)

Forum statistics

Threads
98,022
Messages
948,599
Members
129,281
Latest member
Lehamme
Top