Zalerinian

Spr_Button Anchor Fix

Oct 22nd, 2015
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==========================================================================
  2. // Plugin: Sprite Button Anchor Fix
  3. // Author: Zalerinian
  4. // Version: 1.0.0
  5. // ==========================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported["Spr_ButtonAnchorFix"] = "1.0.0";
  9.  
  10. /*:
  11.  * @plugindesc A plugin to fix click region issues with button sprites when their anchor is not set to 0, 0.
  12.  * @author Zalerinian
  13.  *
  14.  * @help
  15.  * This plugin is plug 'n play, with no configuration. It fixes an issue where
  16.  * sprites of the Sprite_Button class would not have their clickable regions
  17.  * moved if their 'anchor' property was not set to (0, 0)
  18.  */
  19.  
  20. Sprite_Button.prototype.isButtonTouched = function() {
  21.   var x = this.canvasToLocalX(TouchInput.x) + (this.anchor.x * this.width);
  22.   var y = this.canvasToLocalY(TouchInput.y) + (this.anchor.y * this.height);
  23.   return x >= 0 && y >= 0 && x < this.width && y < this.height
  24. };
Advertisement
Add Comment
Please, Sign In to add comment