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,228
Reaction score
11,120
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,228
Reaction score
11,120
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,228
Reaction score
11,120
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,228
Reaction score
11,120
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
10,107
Reaction score
6,397
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

This girl is jealous because I haven't drawn her again in months.
Fr_RrgwaUAAafNa

New sprites in my project!
Updating my stream thumbnail collection here Streaming more game dev in 30 minutes or so. :LZSexcite:

Programming languages are amazing.

Someone needed help with a problem in C#. I've got 0 experience in C#. I read 0 lines of their code. I only knew what they wanted to do. I wrote a completely generic code in Javascript containing the generic answer. But they understood what I was doing and translated that to their code. 20 seconds later, problem solved.
been using ChatGPT to write a new story. I told it to :
generate a word like gundam for a false prophet super AI

it answered :
"NOVUS" as an acronym for "New Omnipotent Virtual Unit for Synthetics"? sounds similar to "gnosis," which is a term associated with knowledge and spiritual enlightenment, fitting the theme of a false prophet.

Forum statistics

Threads
129,813
Messages
1,205,426
Members
170,927
Latest member
The_Milk
Top