| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class Fruit extends cc.Component {
- @property({type:cc.Prefab})
- bubblePrefab:cc.Prefab = null;
- armatureDisplay:dragonBones.ArmatureDisplay;
- index:number;
- type:number;
- willCry:boolean;
- init(index:number,type:number){
- this.index = index;
- this.type = type;
- return this;
- }
- toCry(){
- this.willCry = true;
- }
- onLoad(){
- this.armatureDisplay = this.node.getComponent(dragonBones.ArmatureDisplay);
- if(this.willCry){
- this.cry();
- }else{
- this.node.runAction(cc.repeatForever(cc.sequence(
- cc.moveBy(0.6,cc.v2(0,36)),
- cc.moveBy(0.6,cc.v2(0,-36))
- )));
- this.idle();
- }
- }
- idle(){
- if(this.armatureDisplay.animationName!='idle'+this.type){
- this.armatureDisplay.playAnimation('idle'+this.type,0);
- }
- }
- cry(){
- if(this.armatureDisplay.animationName!='cry'+this.type){
- this.armatureDisplay.playAnimation('cry'+this.type,0);
- }
- }
- bubble(){
- let bubble = cc.instantiate(this.bubblePrefab);
- bubble.setPosition(this.node.position);
- if(this.node.parent){
- this.node.parent.addChild(bubble);
- }
- }
- eat():number[]{
- window.gc.fruitEaten[this.index] = true;
- this.bubble();
- this.node.destroy();
- return [this.type,this.node.x,this.node.y];
- }
- }
|