Fixing a Display Rounding Error where different sized tiles & sprites jitter

62 views Asked by At

I'm making a game in RPG Maker MV which uses Javascript. By default when slow panning speeds are used, events and sprites will improperly round floating values to determine their position on screen. This causes them to appear off from the tilemap by a single pixel. This code snippet fixes that behavior:

var Liquidize = Liquidize || {};
Liquidize.JitterFix = {};
Liquidize.JitterFix.Parameters = PluginManager.parameters('JitterFix');
Liquidize.JitterFix.TileSize = Number(Liquidize.JitterFix.Parameters["Tile Size"]) || 48;

Game_Map.prototype.displayX = function() {
    return Math.floor(this._displayX * Liquidize.JitterFix.TileSize) / Liquidize.JitterFix.TileSize;
};

Game_Map.prototype.displayY = function() {
    return Math.floor(this._displayY * Liquidize.JitterFix.TileSize) / Liquidize.JitterFix.TileSize;
};

Game_Map.prototype.adjustX = function(x) {
    if (this.isLoopHorizontal() &&  x < (this.displayX() - (this.width() -  Liquidize.JitterFix.TileSize) / 2)) {
        x -= this.displayX() + this.width();
    } else {
        x -= this.displayX();
    }
    return x;
};

Game_Map.prototype.adjustY = function(y) {
    if (this.isLoopVertical() && y < (this.displayY() - (this.height() - Liquidize.JitterFix.TileSize) / 2)) {
        y -= this.displayY() + this.height();
    } else {
        y -= this.displayY();
    }
    return y;
};

However, my issue this that my tiles and sprites are different sizes. My tile size is 48 pixels (as shown in the code above) my character sprites are larger... they are 64 pixels.

So right now I'm experiencing an issue where if I set the code above as 48 pixels, the tile events will stay put and not jitter BUT the character sprites will be off. And if I set the code above as 64 pixels, it will be the other way around and the character sprites will stay put and not jitter BUT the tile events will be off.

Therefore I need to adjust this code so that is allows for both the 48px tiles and the 64px character sprites. Anyone know the best way to approach that? Would super appreciate it!!

0

There are 0 answers