Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // jsRPGFaceFlip.js
- //=============================================================================
- /*:
- * @plugindesc Flip faces on the X axis in message boxes
- * @author Brent Farris
- *
- * @help
- * This will flip any face within a message box along the X axis.
- * If the face is looking left they will look right.
- * If it is looking right they will be look left
- *
- */
- // Overriding these two internal functions to force faces to flip
- (function() {
- Window_Base.prototype.drawFace = function(faceName, faceIndex, x, y, width, height) {
- width = width || Window_Base._faceWidth;
- height = height || Window_Base._faceHeight;
- var bitmap = ImageManager.loadFace(faceName);
- var pw = Window_Base._faceWidth;
- var ph = Window_Base._faceHeight;
- var sw = Math.min(width, pw);
- var sh = Math.min(height, ph);
- var dx = Math.floor(x + Math.max(width - pw, 0) / 2);
- var dy = Math.floor(y + Math.max(height - ph, 0) / 2);
- var sx = faceIndex % 4 * pw + (pw - sw) / 2;
- var sy = Math.floor(faceIndex / 4) * ph + (ph - sh) / 2;
- this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy, null, null, true);
- };
- /**
- * Performs a block transfer.
- *
- * @method blt
- * @param {Bitmap} source The bitmap to draw
- * @param {Number} sx The x coordinate in the source
- * @param {Number} sy The y coordinate in the source
- * @param {Number} sw The width of the source image
- * @param {Number} sh The height of the source image
- * @param {Number} dx The x coordinate in the destination
- * @param {Number} dy The y coordinate in the destination
- * @param {Number} [dw=sw] The width to draw the image in the destination
- * @param {Number} [dh=sh] The height to draw the image in the destination
- * @param {Boolean} [flipX=false] Determines if the render should flip on the x axis
- * @param {Boolean} [flipY=false] Determines if the render should flip on the x axis
- */
- Bitmap.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh, flipX, flipY) {
- dw = dw || sw;
- dh = dh || sh;
- if (flipX || flipY) {
- this._context.save();
- if (flipX) {
- this._context.scale(-1, 1);
- dx = dx - (dw * 0.5) - (sw * 0.5);
- }
- if (flipY) {
- this._context.scale(1, -1);
- dy = dy - (dh * 0.5) - (sh * 0.5);
- }
- }
- if (sx >= 0 && sy >= 0 && sw > 0 && sh > 0 && dw > 0 && dh > 0 &&
- sx + sw <= source.width && sy + sh <= source.height) {
- this._context.globalCompositeOperation = 'source-over';
- this._context.drawImage(source._canvas, sx, sy, sw, sh, dx, dy, dw, dh);
- this._setDirty();
- }
- if (flipX || flipY) {
- this._context.restore();
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment