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,178
Reaction score
10,798
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,178
Reaction score
10,798
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,178
Reaction score
10,798
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,178
Reaction score
10,798
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,643
Reaction score
6,151
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 Profile Posts

one of the coolest things I've learned from the forums is the ability to give yourself a hitbox. I have a move you can do on the fields. shoulder tackle. thanks to the forums, that tackle triggers self A switches on some events. NPC's and the environment now react to the tackle. awesome.
I really liked how this one turned out! :kaopride:
WYqMPf6.png

Character (Yes, this is a character): Nibiru the Primal Being from Yugioh.
Dragon Quest style enemy selection plugin work in progress:

Quest_Targeting.png

It's a simple targeting system from the NES era. Select an enemy group; single-target skills will target the first enemy in that group.

Quest-Targeting-Animated.gif
Somehow that granny topic got me... maybe I can come up with some more thematic stuff :3
Going live for tonight's stream! Kytt isn't feeling 100% tonight so the wifestream will be tomorrow and I'll be playing Final Fantasy XIV for this one instead. Twitch

Forum statistics

Threads
121,935
Messages
1,145,269
Members
160,207
Latest member
RiceKun
Top