MV Help fixing VE_SpriteInWindows.js Sprite location is being based on a fixed map x,y, rather than player location x,y.

Hello,

I had thought I had everything working fine and was getting ready to push out an early beta project to play around with, when I noticed the VE_SpriteInWindows plugin I am using wasn't working correctly. Turns out this plugin was never completed (still at v1.00) and the x,y position of the sprite placed in the windows is based on the map, rather than the screen.

Meaning, when one is in the upper top left quadrant of a map, everything works fine. When moving enough distance that the map scrolls, the sprites disappear or lose their arrangement, equivalent to the distance moved. See picture for a visual explanation:


When in the top left corner of the map. Works perfectly.
aligned.png


When moving 10 panels to the right:

unaligned.png


-

Something tells me this wouldn't be impossible to fix, but it is an area I haven't spent much time with yet, so I felt it best to ask for assistance.

This is the piece of code I have been calling when I want to place a sprite in a menu:

Code:
    Window_Base.prototype.drawCharsetSprite = function(battler, x, y, direction, mode, index) {
        var index = index || 0;
        var mode  = mode  || 'always';
        var charsetSprite = this._charsetSprites[index];
        if (!charsetSprite) {
            var sprite = new Sprite_WindowCharset(battler, index, mode);
            this._charsetSprites[index] = sprite;
            this.addChild(sprite);
            sprite.setWindow(this);
            sprite.setCharacter(battler, x, y);
            sprite.setDirection(direction);
        } else if (charsetSprite) {
            charsetSprite.setCharacter(battler, x, y);
            charsetSprite.setDirection(direction);
        }
    };


And here is the code used to call the function. I am calling the middle code: if (parameter.MenuCharset) {

Code:
    Window_MenuStatus.prototype.drawActorFace = function(actor, x, y, width, height) {
        var parameter = VictorEngine.Parameters.SpriteInWindows;
        if (parameter.MenuSprite) {
            var index = $gameParty.members().indexOf(actor);
            this.drawBattlerSprite(actor, x + parameter.SpriteX, y + parameter.SpriteY, parameter.MenuSprite, index);
        }
        if (parameter.MenuCharset) {
            var index = $gameParty.members().indexOf(actor);
            this.drawCharsetSprite(actor, x + parameter.CharsetX, y + parameter.CharsetY, 'down', parameter.MenuCharset, index);
        }
        if (parameter.MenuFace) {
            Window_Base.prototype.drawActorFace.call(this, actor, x, y, width, height);
        }
    };


VE_SpriteInWindows.js in full can be found here on Victor's website: https://victorenginescripts.wordpress.com/rpg-maker-mv/sprite-in-windows/


What am I missing? It seems charsets follow their own rules compared to pictures and faces, which otherwise seem to follow the screen positioning perfectly.

:edit:
Doing some research it seems like the issue is that the sprites are being placed on MAP X,Y instead of SCREEN X,Y. Doing more research to hopefully be able to figure this out.

:edit2:
Sprite_WindowCharset.prototype.setCharacter seems to be the section of code that is problematic (whole section pasted in the spoiler below)

I have found that replacing

this._character.setImage(characterName, characterIndex);
this._spriteX = x + 64;
this._spriteY = y + 64;


with

var spriteKoda = new Sprite(ImageManager.loadCharacter(characterName, characterIndex));
SceneManager._scene.addChild(spriteKoda);
spriteKoda.texture.frame = new Rectangle(0, 0, 64, 64);
spriteKoda.x = x + 296;
spriteKoda.y = y + 42;


is able to accurately place a sprite in the proper screen x,y position, however it causes a duplication of the spritesheet in certain menus. So while var spriteKoda = new Sprite works for the screen x,y, it does not work in the ways that the function setCharacter does in the plugin. Perhaps the way I am using SceneManager to addChild in this particular case is the problem with this approach.

So I am left scratching my head still. A simpler solution seems to be just having the original setImage function base its x,y off of screen position instead of map position. Any and all help is still greatly appreciated for getting this figured out.

Even when changing the spriteY and spriteX to = $gamePlayer.screenX();, the sprites still scroll with the map x,y....

Spoiler: Sprite_WindowCharset
Code:
//=============================================================================
// Sprite_WindowCharset
//=============================================================================

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

Sprite_WindowCharset.prototype = Object.create(Sprite.prototype);
Sprite_WindowCharset.prototype.constructor = Sprite_WindowCharset;

(function() {
 
    Sprite_WindowCharset.prototype.initialize = function(battler, index, mode) {
        Sprite.prototype.initialize.call(this);
        this._mode  = mode;
        this._index = index;
        this.createMainSprite(battler);
    };

    Sprite_WindowCharset.prototype.createMainSprite = function(battler) {
        this._character = new Game_Character();
        this._mainSprite = new Sprite_Character(this._character);
        this.addChild(this._mainSprite);
    };
 
    Sprite_WindowCharset.prototype.setCharacter = function(battler, x, y) {
        this._isDisabled = battler.isDeathStateAffected();
        if (this._isDisabled && battler.downedCharacterName()) {
            var characterName  = battler.downedCharacterName();
            var characterIndex = battler.downedCharacterIndex();
            this._downedDirection = battler.downedDirection();
        } else {
            var characterName  = battler.characterName();
            var characterIndex = battler.characterIndex();
            this._downedDirection = null;
        }
        this._character.setImage(characterName, characterIndex);
        this._character.setStepAnime(battler.canMove());
        this._spriteX = x + 64;
        this._spriteY = y + 64;
        this._mainSprite.update();
        this.update();
    };
 
    Sprite_WindowCharset.prototype.setWindow = function(window) {
        this._window = window;
    };
 

 
})();


Partial Success!
Commenting out the following in // Sprite_WindowCharset:

this._character.setImage(characterName, characterIndex);
this._spriteX = x + 64;
this._spriteY = y + 64;
this._mainSprite.update();
this.update();

And adding the following to Window_Base.prototype.drawCharsetSprite

var characterName = battler.characterName();
var characterIndex = battler.characterIndex();

var spriteKoda = new Sprite(ImageManager.loadCharacter(characterName, characterIndex));
this.addChild(spriteKoda);
spriteKoda.texture.frame = new Rectangle(0, 0, 64, 72);
spriteKoda.x = x + 80;
spriteKoda.y = y + 48;


And replacing this.drawCharsetSprite(actor, x + parameter.CharsetX, y + parameter.CharsetY + 60, 'down'); in Window_SkillStatus.prototype.drawActorFace with the same code added above, but with battler swapped for actor seems to fix every issue except one.

When changing party formation or scrolling through a list of actors, you can see the edges of the previous sprite that was displayed behind the currently displayed sprite. For example a large feathered hat from sprite A will display behind sprite B when their formation position is swapped. So all I need to do is clear the previously displayed sprite somehow. Will keep working on this but any pointers would be highly appreciated.

Original thread: https://forums.rpgmakerweb.com/threads/help-fixing-ve_spriteinwindows-js-sprite-location-is-being-based-on-a-fixed-map-x-y-rather-than-player-location-x-y.166406/