| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import { _decorator, Node, Component, Sprite, Label, Animation, SpriteFrame, AnimationState, systemEvent, Prefab, instantiate, UITransform, Vec3, tween } from 'cc';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- import { Sound } from '../core/sound/Sound';
- import { BitmapFont } from '../core/ui/BitmapFont';
- import { ConfigData } from '../Data/ConfigData';
- import { g } from '../Data/g';
- import { FsUtils } from '../FsUtils/FsUtils';
- const { ccclass, property } = _decorator;
- @ccclass('Role')
- export class Role extends Component {
- @property({ type: Animation, tooltip: "角色特效" }) animation: Animation;
- @property({ type: Label, tooltip: "等级" }) roleLVLabel: Label;
- @property({ type: BitmapFont, tooltip: "金币" }) addMoneyBitmapFont: BitmapFont;
- @property({ tooltip: "金币增长间隔" }) space: number = 2;
- @property({ tooltip: "特效父级", type: Node }) public particleBox: Node;
- @property({ tooltip: "角色图片", type: Sprite }) public roleImg: Sprite;
- @property({ type: Sound, tooltip: "加金币音效" })
- addMoneySound: Sound;
- public generalBaseData: any;//神将数据
- private addMoney: number = 0;
- public generalLv: number = 0;
- public async setData(data: any) {
- this.generalLv = data.lv;
- this.generalBaseData = ConfigData.configMap.get("generalBase")[data.lv];
- this.addMoney = this.generalBaseData.output * this.space;
- let img: SpriteFrame = await ResourcesUtils.load("Roles/" + this.generalBaseData.lv + "/spriteFrame", SpriteFrame, this.node);
- // this.node.getChildByName("roleImg").getComponent(Sprite).spriteFrame = img;
- this.roleImg.spriteFrame = img;
- this.roleLVLabel.string = this.generalBaseData.lv;
- this.addMoneyBitmapFont.string = '+' + FsUtils.moneyFormat(this.addMoney);
- let state = this.animation.getState("role");
- state.wrapMode = 2;
- }
- private onPlayOver() {
- if (g.gameData.playAddMoneySound) {
- this.addMoneySound.play();
- }
- }
- public play() {
- this.animation.play("role");
- }
- public playPrize() {
- this.animation.play("prizeRole");
- }
- //添加粒子特效
- public async addParticle(num: number, starY: number = 100, endYMix: number = 500) {
- for (let i = 0; i < num; i++) {
- let prefab = await ResourcesUtils.load<Prefab>("Prefabs/SpecialEffects/粒子光效", null, this.node);
- let particle = instantiate(prefab);
- particle.parent = this.particleBox;
- let _w = this.particleBox.getComponent(UITransform).width;
- let tempx = Math.random() * (_w * 0.8);
- let _x = tempx > ((_w * 0.8) / 2) ? ((_w * 0.8) / 2) - tempx : tempx;
- particle.setPosition(new Vec3(_x, starY + Math.random() * 200));
- let _scale = Math.random() * 0.5 + 0.5;
- particle.scale = new Vec3(_scale, _scale, 1);
- let endY = Math.random() * 300 + endYMix;
- let endX = Math.random() * (_w + 100);
- endX = endX < ((_w + 100) / 2) ? endX : (_w + 100) / 2 - endX;
- let t = tween(particle);
- t.to(1.5, { position: new Vec3(endX, endY, 0) }).start();
- }
- }
- public roleState(isPrize: boolean) {
- g.gameData.isPlayPrizeRoleAnim = isPrize;
- }
- //#region 新增合成动画、
- //播放合成动画
- public playMerge() {
- this.animation.play("mergeRole");
- }
- //#endregion
- }
|