Draw Sprite via Script (Solved)

Discussion in 'Javascript/Plugin Support' started by orcomarcio, Dec 11, 2015.

  1. orcomarcio

    orcomarcio Veteran Veteran

    Messages:
    97
    Likes Received:
    19
    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: Dec 11, 2015
    #1
  2. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    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);
     
    #2
  3. orcomarcio

    orcomarcio Veteran Veteran

    Messages:
    97
    Likes Received:
    19
    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: Dec 11, 2015
    #3
  4. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    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: Dec 11, 2015
    #4
  5. orcomarcio

    orcomarcio Veteran Veteran

    Messages:
    97
    Likes Received:
    19
    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: Dec 11, 2015
    #5
  6. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    856
    First Language:
    German
    What exactly do you mean by "command line"? You can retrieve the current scene like this, if it helps you:

    Code:
    SceneManager._scene;
     
    #6
  7. orcomarcio

    orcomarcio Veteran Veteran

    Messages:
    97
    Likes Received:
    19
    First Language:
    Italian
    Nice I got it it worked! thank you very much, I really couldn't find the current scene placeholder
     
    #7

Share This Page