123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class MouseSpin extends cc.Component {
- @property(sp.Skeleton)
- spinLizi: sp.Skeleton = null;
- @property(sp.Skeleton)
- spinLight: sp.Skeleton = null;
- @property(cc.Sprite)
- spinRotate: cc.Sprite = null;
- @property(cc.Node)
- spinHover: cc.Node = null;
- @property([cc.SpriteFrame])
- spinRotateImgs: cc.SpriteFrame[] = [];
- private rotateSpeed: number = 110;
- private isSpining = false;
- private needRotate = true;
- private isDark = false;
- protected onLoad(): void {
- this.node.on(cc.Node.EventType.MOUSE_ENTER, () => {
- if (this.isSpining)
- return;
- this.spinHover.active = true;
- }, this);
- this.node.on(cc.Node.EventType.MOUSE_LEAVE, () => {
- if (this.isSpining)
- return;
- this.spinHover.active = false;
- });
- }
- spinStart() {
- this.isSpining = true;
- this.spinHover.active = false;
- this.spinLizi.node.active = true;
- this.spinLizi.setAnimation(0, "btn", false);
- this.spinLizi.setCompleteListener(() => {
- this.spinLizi.setCompleteListener(null);
- this.spinLizi.node.active = false;
- });
- this.spinLight.node.active = true;
- this.spinLight.setAnimation(0, "btn", false);
- this.spinLight.setCompleteListener(() => {
- this.spinLight.setCompleteListener(null);
- this.spinLight.node.active = false;
- });
- this.rotateSpeed = 800;
- cc.tween(this.node)
- .to(0.1, { scale: 0.9 })
- .to(0.1, { scale: 1 })
- .start();
- }
- spinPause() {
- this.spinDark();
- this.needRotate = false;
- }
- spinDark() {
- if (this.isDark)
- return;
- cc.error("========> spinDark");
- this.isDark = true;
- this.spinRotate.spriteFrame = this.spinRotateImgs[1];
- }
- spinOver() {
- this.spinRotate.spriteFrame = this.spinRotateImgs[0];
- this.isSpining = false;
- this.rotateSpeed = 110;
- this.needRotate = true;
- this.isDark = false;
- // this.spinSke.setAnimation(0, "btn", true);
- this.spinLizi.node.active = false;
- this.spinLight.node.active = false;
- }
- protected update(dt: number): void {
- if (!this.needRotate)
- return;
- if (this.spinHover.active) {
- this.spinHover.angle -= this.rotateSpeed * dt;
- }
- this.spinRotate.node.angle -= this.rotateSpeed * dt;
- }
- }
|