12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class Button extends cc.Component {
- @property(cc.SpriteFrame)
- normal: cc.SpriteFrame = null;
- @property(cc.SpriteFrame)
- pressed: cc.SpriteFrame = null;
- @property
- pressedScale: number = 1.1;
- @property
- transDuration: number = 0.1;
- @property([cc.Node])
- private nodes: cc.Node[] = [];
- initScale: number = 0;
- onLoad () {
- // let that = this;
- this.initScale = this.node.scale;
- // function onTouchDown (event) {
- // that.node.getComponent(cc.Sprite).spriteFrame = that.pressed;
- // let scaleDownAction = cc.scaleTo(that.transDuration, that.pressedScale);
- // this.stopAllActions();
- // this.runAction(scaleDownAction);
- // console.log('按下');
-
- // }
- // function onTouchUp (event) {
- // that.node.getComponent(cc.Sprite).spriteFrame = that.normal;
- // let scaleUpAction = cc.scaleTo(that.transDuration, that.initScale);
- // this.stopAllActions();
- // this.runAction(scaleUpAction);
- // }
- // this.node.on('touchstart', onTouchDown, this.node);
- // this.node.on('touchend', onTouchUp, this.node);
- // this.node.on('touchcancel', onTouchUp, this.node);
-
- }
- Show(){
- this.node.getComponent(cc.Sprite).spriteFrame = this.pressed;
- let scaleDownAction = cc.scaleTo(this.transDuration, this.pressedScale);
- this.node.stopAllActions();
- this.node.runAction(scaleDownAction);
- for (let i = 0; i < this.nodes.length; i++) {
- let that = this.nodes[i];
- let button = that.getComponent(Button);
- if(button){
- button.Hide();
- }
- }
- }
- Hide(){
- this.node.getComponent(cc.Sprite).spriteFrame = this.normal;
- let scaleUpAction = cc.scaleTo(this.transDuration, this.initScale||this.node.scale);
- this.node.stopAllActions();
- this.node.runAction(scaleUpAction);
- }
- selected(){
- this.node.getComponent(cc.Sprite).spriteFrame = this.pressed;
- let scaleDownAction = cc.scaleTo(this.transDuration, this.pressedScale);
- this.node.stopAllActions();
- this.node.runAction(scaleDownAction);
- }
- unselected(){
- this.node.getComponent(cc.Sprite).spriteFrame = this.normal;
- let scaleUpAction = cc.scaleTo(this.transDuration, this.initScale||this.node.scale);
- this.node.stopAllActions();
- this.node.runAction(scaleUpAction);
- }
- }
|