Hello community,
I'm currently learning javascript and RPG Maker code structure. In the past, I created successfully sprite button with a clickHandler.
This time, I created a sprite sheet of different runes (similar to the IconSet sheet), but each one is 64 pixels. I was hoping to display Sprite buttons by using the blt method and associate a clickHandler to each of them.
I can successfully display only one rune, but the clickHandler doesn't work.
Obviously, I'm not handling the setClickHandler correctly, but how should I do it ? Unless it's not possible to associate a clickHandler with a blt'd image ?
If that may help :
Thanks in advance,
I'm currently learning javascript and RPG Maker code structure. In the past, I created successfully sprite button with a clickHandler.
This time, I created a sprite sheet of different runes (similar to the IconSet sheet), but each one is 64 pixels. I was hoping to display Sprite buttons by using the blt method and associate a clickHandler to each of them.
I can successfully display only one rune, but the clickHandler doesn't work.
Obviously, I'm not handling the setClickHandler correctly, but how should I do it ? Unless it's not possible to associate a clickHandler with a blt'd image ?
Window_RunesPanel.prototype.drawRune = function(iconIndex) {
var button = new Sprite_Button();
button.bitmap = ImageManager.loadSystem('RuneSet');
var pw = 64;
var ph = 64;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
var dx = (Window_Base._faceWidth - 64) / 2;
var dy = (Window_Base._faceHeight - 64) / 2;
this.contents.blt( button.bitmap, sx, sy, pw, ph, dx,dy);
this._runes.push(button);
button.setClickHandler(this.onButtonDownPanel.bind(this));
};
var button = new Sprite_Button();
button.bitmap = ImageManager.loadSystem('RuneSet');
var pw = 64;
var ph = 64;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
var dx = (Window_Base._faceWidth - 64) / 2;
var dy = (Window_Base._faceHeight - 64) / 2;
this.contents.blt( button.bitmap, sx, sy, pw, ph, dx,dy);
this._runes.push(button);
button.setClickHandler(this.onButtonDownPanel.bind(this));
};
If that may help :
function Window_RunesPanel() {
this.initialize.apply(this, arguments);
};
Window_RunesPanel.prototype = Object.create(Window_Base.prototype);
Window_RunesPanel.prototype.constructor = Window_Characters;
Window_RunesPanel.prototype.initialize = function(x, y) {
var width = Graphics.boxWidth / 2;
var height = Graphics.boxHeight / 2;
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.backOpacity = 0;
this._runes = [];
this.drawRune(0);
}
Window_RunesPanel.prototype.update = function(){
this.refresh();
}
Window_RunesPanel.prototype.onButtonDownPanel = function() {
console.log("Rune Panel : rune number 0 pressed !");
}
Window_RunesPanel.prototype.refresh = function(){
this.contents.clear();
this.drawRune(0);
}
this.initialize.apply(this, arguments);
};
Window_RunesPanel.prototype = Object.create(Window_Base.prototype);
Window_RunesPanel.prototype.constructor = Window_Characters;
Window_RunesPanel.prototype.initialize = function(x, y) {
var width = Graphics.boxWidth / 2;
var height = Graphics.boxHeight / 2;
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.backOpacity = 0;
this._runes = [];
this.drawRune(0);
}
Window_RunesPanel.prototype.update = function(){
this.refresh();
}
Window_RunesPanel.prototype.onButtonDownPanel = function() {
console.log("Rune Panel : rune number 0 pressed !");
}
Window_RunesPanel.prototype.refresh = function(){
this.contents.clear();
this.drawRune(0);
}