Draw Sprite via Script (Solved)

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
Hi,

 I want to draw sprite through code, I don't want to use the existing pitcure system for what I need to do, I want to create a class of my own which you can pass a bitmap to and get it drawn on screen. Maybe there is alredy a class for that but a big part of the code is hidden in MV and i didn't find any in the .js i looked through. The  only usefull thing I found is the "Bitmap" class in the "rpg_core.js" file but it doesn't seem to have a draw() call.

Thank you :)
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
860
First Language
German
Primarily Uses
A big advantage of MV over Ace is, that nothing is hidden, the whole engine is open for you to explore and modify.

You already found the Bitmap class, which is used to load an image from the file system, but you also need to create a Sprite instance to actually display it, like this:

Code:
var sprite = new Sprite(Bitmap.load(...));
This gives you a Sprite object. But to make it visible, you'll need to add it to the current scene, like this:
Code:
scene.addChild(sprite);
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
I can't find scene in the Developer Tool .-.

Could you please like write how for examaple draw a white 20x20 square in the scene?

Something like:

var bitmap = new Bitmap(20, 20);bitmap.fillAll('white');var sprite = new Sprite(bitmap);(scene?).addChild(sprite);Edit: I guess with scene you mean like Scene_Map or something like that, but since I didn't find the addChild() function i guess this class is instatiated with another name, but I can't find it either if that's the case
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
860
First Language
German
Primarily Uses
You are usually inside the scene, when adding sprite.

So, for example, if you want to add said white square to the title screen, you would do it like this:

var aliasCreate = Scene_Title.prototype.create;Scene_Title.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);};Note, that i also added the sprite to the scene under the name "_whiteSquare". This way it's easier to reference it if you want, for example, to move it to a different position at some point./edit, in case you are wondering: What i've done above is that i've aliased the "create" function of the "Scene_Title" class. Every function in Javascript is an object in memory, which automatically gets destroyed, once it's not referenced anymore.

So, i added a new reference to the function (first line), before overwriting it (second line). This way, the old function still exists and i can call it from the new one. This allows me to add to the original function, instead of completely overwriting it.
 
Last edited by a moderator:

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
Ok thank you very much!!

Don't want to insist too much but do you have any idea how to do this through command line? I think I could have more fexibility having also that option :p
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
860
First Language
German
Primarily Uses
What exactly do you mean by "command line"? You can retrieve the current scene like this, if it helps you:

Code:
SceneManager._scene;
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
Nice I got it it worked! thank you very much, I really couldn't find the current scene placeholder
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Note to self: One lemon is enough to flavor my drink.
'I'm not homophobic, I'm not scared of me house.' - Peter Kay xD
When did anything under your mid-twenties become the new 10 years old? At least try to act like your old enough to sign a lease.
Having someone tell me that "Right clicking to save an image is soooo creepy" has got to be the weirdest thing I've heard this week.
Finally figured out how to make a signature with a pic that leads to a link, it's so cool! Click the image to check out my demo! :kaopride:

Forum statistics

Threads
98,180
Messages
950,169
Members
129,484
Latest member
AegeanCaos
Top