How to remove a SceneManager.snapForBackground() ?

Status
Not open for further replies.

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi people!

I have two scenes and two windows in my custom plugin.

Scene_Language > Window_Language(Based on window_options).
Scene_Confirmation > Window_Confirmation.

As soon as the Scene_language opens, the window language also opens and a option appears for the player choose.
The player make a choice.
i call the SceneManager.snapForBackground()
the Scene_Confirmation opens(and the background for it, is the Image of the previous Scene), and so the Window_Confirmation.
If the player choose "YES", everything works fine, and he goes to the sceneMap.
But, if the player choose "NO", he comes back to the Scene_Language.
But the background still there, so when the window open again it causes like a duplicate of the background making the screen more dark.

Here is a video to show better what i'm trying to explain:

[[[EDIT]]]] - Code Updated

And here is the code:
Code:
//=================================================================================
// SCENE LANGUAGE (SCENE_MENUBASE)
//=================================================================================

function Scene_Language() {
    this.initialize.apply(this, arguments);
    this.removeChild(this._spriteset);
    SceneManager.snap();
}

Scene_Language.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Language.prototype.constructor = Scene_Language;

Scene_Language.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Language.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createWindowLayer();
    this.createLanguageWindow();
    this.createConfirmationWindow();
};

Scene_Language.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
    ConfigManager.save();
};

Scene_Language.prototype.createLanguageWindow = function() {
    this._languageWindow = new Window_Language();
    this._languageWindow.setHandler('cancel', this.popScene.bind(this));
    this.addWindow(this._languageWindow);
};

Scene_Language.prototype.createConfirmationWindow = function() {
    this._commandWindow = new Window_Confirmation();
    this._commandWindow.setHandler('Yes',  this.commandYes.bind(this));
    this._commandWindow.setHandler('No',   this.commandNo.bind(this));
    this.addChild(this._commandWindow);
};

Scene_Language.prototype.commandYes = function() {
    SceneManager.goto(Scene_Map);
};

Scene_Language.prototype.commandNo = function() {
    this._commandWindow.close();//SceneManager.pop();
};

//=================================================================================
// WINDOW LANGUAGE (WINDOW_COMMAND)
//=================================================================================

function Window_Language() {
    this.initialize.apply(this, arguments);
}

Window_Language.prototype = Object.create(Window_Command.prototype);
Window_Language.prototype.constructor = Window_Language;

Window_Language.prototype.initialize = function() {
    Window_Command.prototype.initialize.call(this, 0, 0);
    this.updatePlacement();
    this.idiomaflagA();
    this.idiomaflagB();
};
   
Window_Language.prototype.Opacity = function() {
    return 255;
};

Window_Language.prototype.standardBackOpacity = function() {
    return 180;
};

Window_Language.prototype.idiomaflagA = function() {
    this._flaga = new Sprite();
    this._flaga.move(200, 200, 0, 0);
    this._flaga.bitmap = ImageManager.loadSystem('red');
    this._flaga.height = this.windowHeight();
    this._flaga.opacity = 255;
    this.addChildAt(this._flaga, 1); // 0 = Layer
};

Window_Language.prototype.idiomaflagB = function() {
    this._flagb = new Sprite();
    this._flagb.move(400, 200, 0, 0);
    this._flagb.bitmap = ImageManager.loadSystem('blue');
    this._flagb.height = this.windowHeight();
    this._flagb.opacity = 50;
    this.addChildAt(this._flagb, 1); // 0 = Layer
};

Window_Language.prototype.windowWidth = function() {
    return Graphics.boxWidth;
};

Window_Language.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_Language.prototype.updatePlacement = function() {
    this.x = 0;
    this.y = 0;
};

Window_Language.prototype.makeCommandList = function() {

};

Window_Language.prototype.drawItem = function(index) {
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawText(this.commandName(index), rect.x, rect.y, titleWidth, 'left');
    this.drawText(this.statusText(index), titleWidth, rect.y, statusWidth, 'right');
};

Window_Language.prototype.cursorRight = function(wrap) {
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    this.changeValue(symbol, true);

};

Window_Language.prototype.cursorLeft = function(wrap) {
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    this.changeValue(symbol, false);
};

Window_Language.prototype.statusWidth = function() {
    return (Graphics.boxWidth /2);
};

Window_Language.prototype.changeValue = function(symbol, value) {
    var lastValue = this.getConfigValue(symbol);
    if (lastValue !== value) {
        this.setConfigValue(symbol, value);
        this.redrawItem(this.findSymbol(symbol));
        SoundManager.playCursor();
}
};

Window_Language.prototype.getConfigValue = function(symbol) {
    return ConfigManager[symbol];
};

Window_Language.prototype.setConfigValue = function(symbol, volume) {
    ConfigManager[symbol] = volume;
};

Window_Language.prototype.update = function() {
    if(Input.isTriggered('right')) {
        this._flagb.opacity = 255;
        this._flaga.opacity = 50;
        this.cursorRight();
    }
    if(Input.isTriggered('left')) {
        this._flagb.opacity = 50;
        this._flaga.opacity = 255;
        this.cursorLeft();
    }
    if(Input.isTriggered('ok')) {
        this._confirmationWindow.open();
        // this._confirmationWindow.activate();
    }
};

//=================================================================================
// WINDOW CONFIRMATION (WINDOW_COMMAND)
//=================================================================================

function Window_Confirmation() {
    this.initialize.apply(this, arguments);
}

Window_Confirmation.prototype = Object.create(Window_Command.prototype);
Window_Confirmation.prototype.constructor = Window_Confirmation;

Window_Confirmation.prototype.initialize = function() {
    Window_Command.prototype.initialize.call(this, 0, 0);
    this.openness = 0;
    this.close();
    this.updatePlacement();
    //this.deactivate();
   
};

Window_Confirmation.prototype.windowWidth = function() {
    return 240;
};

Window_Confirmation.prototype.updatePlacement = function() {
    this.x = (Graphics.boxWidth - this.width) / 2;
    this.y = (Graphics.boxHeight - this.height) / 2;
};

Window_Confirmation.prototype.makeCommandList = function() {
    this.addCommand('Yes', 'Yes');
    this.addCommand('No',  'No');
};
:kaodes:
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Remember the KISS principle.
For example why in the world do you stack Scene_Confirmation on Scene_Language? Why not just make a Window_Confirmation that's initially closed and inactive and then activate it upon proper input? If yes, SceneManager.pop, if no, deactivate the confirmation window and hide it and activate the window back.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
Remember the KISS principle.
For example why in the world do you stack Scene_Confirmation on Scene_Language? Why not just make a Window_Confirmation that's initially closed and inactive and then activate it upon proper input? If yes, SceneManager.pop, if no, deactivate the confirmation window and hide it and activate the window back.
UHAUHUAHUAHUAUHA
Man, i try like hell to do that. But i cant get it =/
i manage to make the two windows in the same scene. But i can't make the window confirmation open.
I try with
.open
.activate
But i cant get it.
That was my first idea :(
I will try more tomorrow!
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
It may be hidden. In this case you may need to use .show before the .open
And of course layering matters too, so the order in which you add them to the window layer matters. It is definitely doable though, I have been able to shift six command window prototypes, one of them dual use, and two selectable window prototypes in one scene with no issues.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
It may be hidden. In this case you may need to use .show before the .open
And of course layering matters too, so the order in which you add them to the window layer matters. It is definitely doable though, I have been able to shift six command window prototypes, one of them dual use, and two selectable window prototypes in one scene with no issues.
**I updated the code in the first post***

Well, i manage to put the two windows open in the same scene. And manipulate both at the same time.
As soon as the scene begins, the two windows open.

But i want to only the first one open. And after that the window confirmation. so i made this:

Code:
Window_Confirmation.prototype.initialize = function() {
    Window_Command.prototype.initialize.call(this, 0, 0);
    this.openness = 0;
    this.close();
    this.updatePlacement();
};
The problem is, that now, i can make it open through the first window

Code:
Window_Language.prototype.update = function() {
    if(Input.isTriggered('right')) {
        this._flagb.opacity = 255;
        this._flaga.opacity = 50;
        this.cursorRight();
    }
    if(Input.isTriggered('left')) {
        this._flagb.opacity = 50;
        this._flaga.opacity = 255;
        this.cursorLeft();
    }
    if(Input.isTriggered('ok')) {
        // this._confirmationWindow.open();
        // this._confirmationWindow.activate();
//this.Window_Confirmation.open();
//this._commandWindow.open(Window_Confirmation);
    }
};
tried all "this._" codes (one at the time) but they always gave me this error:
Code:
TypeError: Cannot read property 'open' of undefined
    at Window_Language.update (Eli_Scene_Language2.js:171)
    at rpg_core.js:7035
    at Array.forEach (<anonymous>)
    at WindowLayer.update (rpg_core.js:7033)
    at rpg_scenes.js:262
    at Array.forEach (<anonymous>)
    at Scene_Language.Scene_Base.updateChildren (rpg_scenes.js:260)
    at Scene_Language.Scene_Base.update (rpg_scenes.js:113)
    at Function.SceneManager.updateScene (rpg_managers.js:2024)
    at Function.SceneManager.updateMain (rpg_managers.js:1983)
So you talk about the window layers.
I create the windows in scene like this:
Code:
Scene_Language.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createWindowLayer();
    this.createLanguageWindow();
    this.createConfirmationWindow();
};

Scene_Language.prototype.createLanguageWindow = function() {
    this._languageWindow = new Window_Language();
    this._languageWindow.setHandler('cancel', this.popScene.bind(this));
    this.addWindow(this._languageWindow);
};

Scene_Language.prototype.createConfirmationWindow = function() {
    this._commandWindow = new Window_Confirmation();
    this._commandWindow.setHandler('Yes',  this.commandYes.bind(this));
    this._commandWindow.setHandler('No',   this.commandNo.bind(this));
    this.addChild(this._commandWindow);
};
the order that i create them defines the layer level of each one?
Now i am completely lost =/
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
No wonder. You are creating a this._commandWindow in the createConfirmationWindow function,
but using this._confirmationWindow.open.
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
No wonder. You are creating a this._commandWindow in the createConfirmationWindow function,
but using this._confirmationWindow.open.
Not sure if I understand you, but i already tried this line of code, and give me the same error :/
You are saying that are something wrong in the function create Confirmation window?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Code:
Window_Language.prototype.update = function() {
if(Input.isTriggered('right')) {
this._flagb.opacity = 255;
this._flaga.opacity = 50;
this.cursorRight();
}
if(Input.isTriggered('left')) {
this._flagb.opacity = 50;
this._flaga.opacity = 255;
this.cursorLeft();
}
if(Input.isTriggered('ok')) {
this._confirmationWindow.open();
// this._confirmationWindow.activate();
}
};
This function contains
this._confirmationWindow.open().
However, you don't have a confirmation window.
You only have a command window according to
Code:
Scene_Language.prototype.createConfirmationWindow = function() {
   this._commandWindow = new Window_Confirmation();
   this._commandWindow.setHandler('Yes',  this.commandYes.bind(this));
   this._commandWindow.setHandler('No',   this.commandNo.bind(this));
   this.addChild(this._commandWindow);
};
Also, not this._confirmationWindow, since Window_Language is not Scene_Language.

This should fix the issue.
Code:
Window_Language.prototype.update = function() {
if(Input.isTriggered('right')) {
this._flagb.opacity = 255;
this._flaga.opacity = 50;
this.cursorRight();
}
if(Input.isTriggered('left')) {
this._flagb.opacity = 50;
this._flaga.opacity = 255;
this.cursorLeft();
}
if(Input.isTriggered('ok')) {
SceneManager._scene._commandWindow.open();
// this._confirmationWindow.activate();
}
};
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,695
Reaction score
1,113
First Language
Portuguese - Br
Primarily Uses
RMMZ
Code:
Window_Language.prototype.update = function() {
if(Input.isTriggered('right')) {
this._flagb.opacity = 255;
this._flaga.opacity = 50;
this.cursorRight();
}
if(Input.isTriggered('left')) {
this._flagb.opacity = 50;
this._flaga.opacity = 255;
this.cursorLeft();
}
if(Input.isTriggered('ok')) {
this._confirmationWindow.open();
// this._confirmationWindow.activate();
}
};
This function contains
this._confirmationWindow.open().
However, you don't have a confirmation window.
You only have a command window according to
Code:
Scene_Language.prototype.createConfirmationWindow = function() {
   this._commandWindow = new Window_Confirmation();
   this._commandWindow.setHandler('Yes',  this.commandYes.bind(this));
   this._commandWindow.setHandler('No',   this.commandNo.bind(this));
   this.addChild(this._commandWindow);
};
Also, not this._confirmationWindow, since Window_Language is not Scene_Language.

This should fix the issue.
Code:
Window_Language.prototype.update = function() {
if(Input.isTriggered('right')) {
this._flagb.opacity = 255;
this._flaga.opacity = 50;
this.cursorRight();
}
if(Input.isTriggered('left')) {
this._flagb.opacity = 50;
this._flaga.opacity = 255;
this.cursorLeft();
}
if(Input.isTriggered('ok')) {
SceneManager._scene._commandWindow.open();
// this._confirmationWindow.activate();
}
};
Man! Thank you for your time. I think this command of code "
SceneManager._scene._commandWindow.open();" that was looking for.
It works! Everything works fine now.

Also i change the function
Code:
Scene_Language.prototype.createConfirmationWindow = function() {
   this._commandWindow = new Window_Confirmation();
   this._commandWindow.setHandler('Yes',  this.commandYes.bind(this));
   this._commandWindow.setHandler('No',   this.commandNo.bind(this));
   this.addChild(this._commandWindow);
};
to

Code:
Scene_Language.prototype.createConfirmationWindow = function() {
    this._confirmationWindow = new Window_Confirmation();
    this._confirmationWindow.setHandler('Yes',  this.commandYes.bind(this));
    this._confirmationWindow.setHandler('No',   this.commandNo.bind(this));
    this.addChild(this._confirmationWindow);
};
and the used
SceneManager._scene._confirmationWindow.open();

All things still worked.
Do you advice me keep this change that i made in the function? Or its doens't matter at all?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Javascript engine doesn't really care, but for a human it's more readable this way, so I'd keep the change.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,533
First Language
English
Primarily Uses
RMMV

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.

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top