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,158
Reaction score
10,730
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,158
Reaction score
10,730
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,158
Reaction score
10,730
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,158
Reaction score
10,730
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
9,112
Reaction score
5,963
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

Climbing to the top #mapping
1638160732198.png
I've started the first steps of the final few maps that I need to make for B:ms. I haven't been able to say that in a really, really long time. It'd probably be a good idea to blog about this or something.
Question for the Mods: What am I supposed to do when I can't make a synopsis 350 words long? (for project recruitment thread) @Shaz @mlogan
The game is meant to be more on the simple side in order to be achievable so I'm a bit stuck...
Had a nice visit with our family. Dad grilled some burgers and mom made baked beans and fudge. We also watched Foul Play. Chevy Chase and Goldie Hawn make an awesome duo. I am surprised how much of the movie I forgot LOL. How did everyone else's holidays go?

Forum statistics

Threads
117,041
Messages
1,104,048
Members
152,976
Latest member
BeastBanks
Top