| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- cc.Class({
- extends: cc.Component,
- properties: {
- GameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- ChiVoice: {
- default: null,
- type: cc.AudioClip,
- serializable: true,
- },
- },
- start () {
- this.GirlAnimations = this.GameStates.getComponent('GameStates').GirlAnimations;
- //获取 ArmatureDisplay
- this._armatureDisPlay = this.node.getComponent(dragonBones.ArmatureDisplay);
- this._armature = this._armatureDisPlay.armature();
- //Hide HeadPhone
- // this.slot = this._armature.getSlot('erji');
- // this.slot.visible = false;
- //Add Animation Callback
- this._armatureDisPlay.addEventListener(dragonBones.EventObject.START, this.animationEventHandler, this);
- this._armatureDisPlay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
- // Is playing any animation
- this.BPlayingAnimation = false;
- // 重复次数
- let repeat = cc.REPEAT_FOREVER;
- // 以秒为单位的时间间隔
- let interval = 10;
- // 开始延时
- let delay = 0;
- this.schedule(function()
- {
- if(!this.BPlayingAnimation)
- {
- // let RandNum = this.Rand(0,100);
- // if(RandNum>20)
- // {
- // this.Idle( 2);
- // }
- // else
- // {
- // this.Happy( 1);
- // }
- let RandBool = this.Rand(0,1);
- let RandNum = this.Rand(0,this.GirlAnimations.length-1);
- let AnimName = this.GirlAnimations[0,RandNum];
- if(RandBool==0)
- {
- if(AnimName == 'Idle')
- {
- this.Idle( 1);
- let RandNum100 = this.Rand(0,100);
- if(RandNum100<20)
- {
- cc.audioEngine.playEffect(this.ChiVoice, false);
- }
- }
- }
- }
- }, interval, repeat, delay);
- },
- Idle(PlayTimes){
- if(this.GirlAnimations.indexOf('Idle')==-1) return;
- this._armatureDisPlay.timeScale =2;
- this._armatureDisPlay.playAnimation('Idle', PlayTimes);
- },
- Happy(PlayTimes){
- if(this.GirlAnimations.indexOf('Happy')==-1) return;
- this._armatureDisPlay.timeScale =2;
- this._armatureDisPlay.playAnimation('Happy',PlayTimes);
- },
- Shy(){
- if(this.GirlAnimations.indexOf('Shy')==-1) return;
- if(this.BPlayingAnimation) return;
- this._armatureDisPlay.timeScale =2;
- this._armatureDisPlay.playAnimation('Shy', 1);
- },
- Angry(){
- if(this.GirlAnimations.indexOf('Angry')==-1) return;
- if(this.BPlayingAnimation) return;
- this._armatureDisPlay.timeScale =2;
- this._armatureDisPlay.playAnimation('Angry', 1);
- },
- animationEventHandler: function animationEventHandler(event) {
- if (event.type == dragonBones.EventObject.START) {
- this.BPlayingAnimation = true;
- // cc.log('START='+this._armatureDisPlay.animationName);
- } else if (event.type == dragonBones.EventObject.COMPLETE) {
- // cc.log('COMPLETE='+this._armatureDisPlay.animationName);
- this.BPlayingAnimation = false;
- }
- },
- Rand(star, end){
- let random = Math.floor(Math.random()*(end-star+1)+star);
- return random;
- },
- });
|