We’ve been using images to change the look of buttons when we mouse-over and/or select buttons. This is pretty straightforward, but we decided to see if we can get the same effects using the editor. One of the key effects is that we shift the text slightly up and to the left and add a drop shadow so that it appears that the text lifts. I’ve managed to make this work, but I’m bothered by the apparent need to change the contents of the text attribute of the element in order to get the change in the shadow to update. This seems like a silly kludge to me. Surely there is something I’m missing.
Btn_Go2_Test.prototype.onEnter = function (event) {
this.hovered = true;
event.element.materialAsset = this.hoverAsset1;
this.btnRSERFS.element.shadowOffset = new pc.Vec2(0.2,-0.2);
this.btnRSERFS.translateLocal(-2,2,0);
this.memLabel= this.btnRSERFS.element.text; // save the text for the element
this.btnRSERFS.element.text = ""; //change the text so that shadows will update
this.btnRSERFS.element.text = this.memLabel; //restore the text for the element
// set our cursor to a pointer
document.body.style.cursor = 'pointer';
};
// When the cursor leaves the element assign the original texture & restore the text element
Btn_Go2_Test.prototype.onLeave = function (event) {
this.hovered = false;
event.element.materialAsset = this.originalMaterial;
this.btnRSERFS.element.shadowOffset = new pc.Vec2(0,0);
this.btnRSERFS.translateLocal(2,-2,0);
this.memLabel= this.btnRSERFS.element.text; // save the text for the element
this.btnRSERFS.element.text = ""; //change the text so that shadows will update
this.btnRSERFS.element.text = this.memLabel; //restore the text for the element
// go back to default cursor
document.body.style.cursor = 'default';
};