[SOLVED] How do I "draw" a white square on the screen?

Discussion in 'Learning Javascript' started by Cheesy, Nov 14, 2018.

Thread Status:
Not open for further replies.
  1. Cheesy

    Cheesy Villager Member

    Messages:
    5
    Likes Received:
    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: Nov 15, 2018
    #1
  2. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,927
    Likes Received:
    9,920
    Location:
    Czech Republic
    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.
     
    #2
  3. Cheesy

    Cheesy Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    But I also don't know how to set textures, so any explanation on that would be appriciated as well.
     
    #3
  4. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,927
    Likes Received:
    9,920
    Location:
    Czech Republic
    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: Nov 14, 2018
    #4
  5. Cheesy

    Cheesy Villager Member

    Messages:
    5
    Likes Received:
    0
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    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.
     
    #5
  6. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,927
    Likes Received:
    9,920
    Location:
    Czech Republic
    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?
     
    #6
    Cheesy likes this.
  7. Cheesy

    Cheesy Villager Member

    Messages:
    5
    Likes Received:
    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!
     
    #7
  8. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,927
    Likes Received:
    9,920
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Yeah, according to forum rules you should make another thread for it.
     
    #8
  9. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,538
    Likes Received:
    4,121
    Location:
    Belgium
    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.

     
    #9
Thread Status:
Not open for further replies.

Share This Page