123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- export enum EasingEnum {
- quadIn = 0,
- quadOut = 1,
- quadInOut = 2,
- cubicIn = 3,
- cubicOut = 4,
- cubicInOut = 5,
- quartIn = 6,
- quartOut = 7,
- quartInOut = 8,
- quintIn = 9,
- quintOut = 10,
- quintInOut = 11,
- sineIn = 12,
- sineOut = 13,
- sineInOut = 14,
- expoIn = 15,
- expoOut = 16,
- expoInOut = 17,
- circIn = 18,
- circOut = 19,
- circInOut = 20,
- elasticIn = 21,
- elasticOut = 22,
- elasticInOut = 23,
- backIn = 24,
- backOut = 25,
- backInOut = 26,
- bounceIn = 27,
- bounceOut = 28,
- bounceInOut = 29,
- smooth = 30,
- fade = 31
- }
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class NewClass extends cc.Component {
- @property({ type: cc.Enum(EasingEnum) })
- public easings: EasingEnum = EasingEnum.smooth;
- @property
- duration: number = 2;
- @property
- isScale: boolean = false;
- @property
- startScale: number = 2;
- @property
- targetScale: number = 1;
- /**初始隐藏 */
- @property
- isStartHide: boolean = false;
- @property
- isMove: boolean = false;
- @property(cc.Vec3)
- startPos: cc.Vec3 = new cc.Vec3(0, 50, 0);
- @property(cc.Vec3)
- endPos: cc.Vec3 = new cc.Vec3(0, 0, 0);
- @property
- isInterval: boolean = false;
- @property
- intervalTime: number = 1;
- @property
- isLoop: boolean = false;
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.Init();
- (this.isInterval) ? this.scheduleOnce(() => { this.TweenFunc(); }, this.intervalTime) : this.TweenFunc();
- }
- private Init() {
- if (this.isMove) this.node.position = this.startPos;
- if (this.isScale) this.node.setScale(this.startScale);
- if (this.isStartHide) this.node.opacity = 0;
- }
- private TweenFunc() {
- if (this.isStartHide) this.node.opacity = 255;
- let tweens = cc.tween();
- //, position: this.currentPos
- if (this.isScale) tweens.to(this.duration, { scale: this.targetScale }, { easing: EasingEnum[this.easings] });
- if (this.isMove) tweens.to(this.duration, { position: this.endPos }, { easing: EasingEnum[this.easings] });
- tweens.call(() => {
- // this.node.setScale(this.startScale);
- console.log('缓动结束回调');
- // if (this.callback) this.callback();
- });
- (this.isLoop) ? cc.tween(this.node).repeatForever(tweens).start() : cc.tween(this.node).repeat(1, tweens).start();
- }
- // update (dt) {}
- }
|