Hi all, I added a Window_Command object to Scene_Map, but when I click on the options or other parts of the window, the player moves to where I clicked. This indicates that the window's touch response was passed to the map scene. I want to prevent the Window_Command object from passing a touch response to its parent container, and was wondering if there was any way to do this.
MZ How to stop a window's touch or click events from being passed to the parent scene
Learning Javascripthow did you create the window?
so far I know, windows on scene map don't free the game, as you can make
hugs, or elements on the map, so you have to make the scene different and
make it on Scene_Base instead of Scene_Map
so far I know, windows on scene map don't free the game, as you can make
hugs, or elements on the map, so you have to make the scene different and
make it on Scene_Base instead of Scene_Map
If i'm wrong please correct me, but i feel like you are looking at this the wrong way.
You should be looking at why the player is usually unable to move when a window is present on the map scene.
The method responsible for allowing the player to move is:
Right off the bat we can see the player isn't allowed to move when an event is running or the message window is busy.
I would like to add that the message object's "isBusy" method is responsible for more than the message window.
So that's already a couple of windows that you would usually encounter on the map scene.
Without stretching this any further, what i'm trying to say is that the player movement method should be altered to account for your custom window.
You should be looking at why the player is usually unable to move when a window is present on the map scene.
The method responsible for allowing the player to move is:
JavaScript:
Game_Player.prototype.canMove
Right off the bat we can see the player isn't allowed to move when an event is running or the message window is busy.
JavaScript:
if ($gameMap.isEventRunning() || $gameMessage.isBusy()) {
return false;
}
I would like to add that the message object's "isBusy" method is responsible for more than the message window.
JavaScript:
Game_Message.prototype.isBusy = function() {
return (
this.hasText() ||
this.isChoice() ||
this.isNumberInput() ||
this.isItemChoice()
);
};
So that's already a couple of windows that you would usually encounter on the map scene.
Without stretching this any further, what i'm trying to say is that the player movement method should be altered to account for your custom window.
Sorry, maybe I didn't express my question clearly.
Actually, essentially I'm trying to figure out how to disable the PIXI.Container's child Container from passing touch responses to the father Container. Scene_Map and Window_Command are both subclasses of PIXI.Container, and I'm trying to figure out how to cut off the touch response between Containers. When my customized Window_Command window comes up, the player should only not move if the touch response is within the borders of my customized window, when the touch response is outside the window, the player should move normally even if the window appears.
My window is added directly to the Scene_Map, and this window must be in the map scene, because the player is free to move around while this window appears
Thanks to the image you posted i understand what you want to accomplish.
So i went ahead and attempted to see if i could get something to work, and i did.
I started by looking into Window_Scrollable since i remember it had a method for checking touch input and indeed it does: Window_Scrollable.prototype.isTouchedInsideFrame
And thankfully Window_Command does inherit Window_Scrollable's methods as well so we can make use of this.
I started by modifying the "isTouchedInsideFrame" method to include a "TouchInput.isTriggered" so that the method would return true only if we press the contents of the window, not hover them.
Afterwards you can alias the player movement method to check for your window.
NOTE: Alternatively you could alias the Scene_Map.prototype.isMapTouchOk method if you create your window directly on the scene map.
And here's my very crude working code that you can test in your dev tools:
So i went ahead and attempted to see if i could get something to work, and i did.
I started by looking into Window_Scrollable since i remember it had a method for checking touch input and indeed it does: Window_Scrollable.prototype.isTouchedInsideFrame
And thankfully Window_Command does inherit Window_Scrollable's methods as well so we can make use of this.
I started by modifying the "isTouchedInsideFrame" method to include a "TouchInput.isTriggered" so that the method would return true only if we press the contents of the window, not hover them.
JavaScript:
Window_Scrollable.prototype.isTouchedInsideFrame = function() {
const touchPos = new Point(TouchInput.x, TouchInput.y);
const localPos = this.worldTransform.applyInverse(touchPos);
return this.innerRect.contains(localPos.x, localPos.y) && TouchInput.isTriggered();
};
Afterwards you can alias the player movement method to check for your window.
JavaScript:
Game_Player.prototype.canMove = function() {
if (win.isTouchedInsideFrame()) {
return false;
} else {
return player_alias.call(this);
}
};
NOTE: Alternatively you could alias the Scene_Map.prototype.isMapTouchOk method if you create your window directly on the scene map.
And here's my very crude working code that you can test in your dev tools:
JavaScript:
// create a test window
let rect = new Rectangle(0, 0, 300, 300);
let win = new Window_Scrollable(rect);
SceneManager._scene.addWindow(win);
// modify touch method
Window_Scrollable.prototype.isTouchedInsideFrame = function() {
const touchPos = new Point(TouchInput.x, TouchInput.y);
const localPos = this.worldTransform.applyInverse(touchPos);
return this.innerRect.contains(localPos.x, localPos.y) && TouchInput.isTriggered();
};
// check if the window was touched
let win_alias = win.update;
win.update = function() {
win_alias.call(this);
if (this.isTouchedInsideFrame()) {
console.log("touched");
}
}
// modify valid movement check
let player_alias = Game_Player.prototype.canMove;
Game_Player.prototype.canMove = function() {
if (win.isTouchedInsideFrame()) {
return false;
} else {
return player_alias.call(this);
}
};
Thank you, I seem to be halfway there, now the player can move correctly while the window is displayed, but I can't seem to scroll my window with the mouse wheel!
JavaScript:
isTouchedInsideFrameForWheelScroll() {
const touchPos = new Point(TouchInput.x, TouchInput.y);
const localPos = this.worldTransform.applyInverse(touchPos);
return this.innerRect.contains(localPos.x, localPos.y);
}
processWheelScroll () {
if (this.isWheelScrollEnabled() && this.isTouchedInsideFrameForWheelScroll()) {
const threshold = 20;
if (TouchInput.wheelY >= threshold) {
this.smoothScrollDown(1);
}
if (TouchInput.wheelY <= -threshold) {
this.smoothScrollUp(1);
}
}
};
I'm using it as a solution, but I don't know if there are any hidden pitfalls.
My bad, it would seem that the scroll operation does require the isTouchedInsideFrame method.
see: Window_Scrollable.prototype.processTouchScroll
Instead of modifying isTouchedInsideFrame directly you could instead use it together with the TouchInput.isTriggered in either Game_Player.prototype.canMove or Scene_Map.prototype.isMapTouchOk
Example:
see: Window_Scrollable.prototype.processTouchScroll
Instead of modifying isTouchedInsideFrame directly you could instead use it together with the TouchInput.isTriggered in either Game_Player.prototype.canMove or Scene_Map.prototype.isMapTouchOk
Example:
JavaScript:
// player method
Game_Player.prototype.canMove = function() {
if (win.isTouchedInsideFrame() && TouchInput.isTriggered()) {
return false;
} else {
return player_alias.call(this);
}
};
// map method
Scene_Map.prototype.isMapTouchOk = function() {
return this.isActive() && $gamePlayer.canMove() && win.isTouchedInsideFrame() && TouchInput.isTriggered();
};
Thank you, but putting TouchInput.isTriggered() into isMapTouchOk seems to cause a problem, the player doesn't move to the clicked point on the map, but only one frame! But the second method you gave me has solved my problem!
Original thread: https://forums.rpgmakerweb.com/threads/how-to-stop-a-windows-touch-or-click-events-from-being-passed-to-the-parent-scene.170075/