| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import BtnClosePanel from "../../component/BtnClosePanel";
- import { AdFun } from "../../data/AdData";
- import TurnableItem from "./TurnableItem";
- const { ccclass, property } = cc._decorator;
- /**
- * 转盘
- * @author 邹勇 kaka
- */
- @ccclass
- export default class Turnable extends cc.Component {
- @property(cc.Node)
- node_turn: cc.Node = null;
- @property(cc.Node)
- node_items: cc.Node[] = [];
- @property(cc.Node)
- btn_draw: cc.Node = null;
- @property(cc.Sprite)
- btn_close: cc.Sprite = null;
- @property(cc.RichText)
- lbl_left: cc.RichText = null;
- private audioId: number;
- private endAngle = 0
- private startDraw = false
- private slowDis = 720
- private slowAngle = 0
- private perAdd = 10
- private perMinus = 0
- onLoad() {
- this.initData();
- }
- /**
- * 初始化奖励和抽奖次数
- */
- private initData() {
- if (gData.turnable.config) {
- for (let i = 0; i < gData.turnable.config.length; i++) {
- let sc = this.node_items[i].getComponent(TurnableItem);
- sc.initData(gData.turnable.config[i].type);
- }
- }
- gData.turnable.requestData();
- this.updateLeftTimes();
- }
- /** 点击抽奖 */
- clickDraw() {
- if (gData.turnable.leftTimes > 0) {
- mk.ad.watchAd((success: boolean) => {
- mk.console.log("watchAD:" + success);
- if (success) {
- gData.adData.watchVideo(AdFun.turntable);
- }
- });
- }
- // this.play(2);
- }
- private async play(index) {
- this.audioId = await mk.audio.playEffect("turnableplay", true);
- this.btn_close.getComponent(BtnClosePanel).block_click = true;
- this.perAdd = 10
- this.node_turn.angle += 360 * 5
- this.endAngle = index * -60
- this.slowAngle = this.endAngle + this.slowDis
- this.perMinus = this.perAdd / (this.slowDis / (this.perAdd * 0.5))
- this.startDraw = true
- // this.node_turn.angle = 1800;
- // let tar = index * 60;
- // cc.tween(this.node_turn)
- // .to(3, { angle: tar })
- // .call(this.playOver, this).start();
- }
- private playOver() {
- mk.audio.stopEffect(this.audioId);
- this.btn_close.getComponent(BtnClosePanel).block_click = false;
- this.updateLeftTimes();
- mk.ui.openPanel("module/reward/reward");
- }
- updateLeftTimes() {
- this.lbl_left.string = `剩余:<color=#FFED99>${gData.turnable.leftTimes}</color>次`;
- }
- update() {
- if (gData.turnable.requestFinish) {
- this.updateLeftTimes();
- gData.turnable.requestFinish = false;
- }
- if (gData.turnable.adData) {
- this.play(2);
- gData.reward.data = gData.turnable.adData;
- gData.turnable.adData = null;
- }
- if (this.startDraw) {
- this.node_turn.angle -= this.perAdd
- //开始减速
- if (this.node_turn.angle <= this.slowAngle) {
- if (this.perAdd <= this.perMinus * 4) {
- this.perAdd -= this.perMinus * 0.01
- }
- else {
- this.perAdd -= this.perMinus
- }
- }
- if (this.node_turn.angle <= this.endAngle) {
- this.startDraw = false
- }
- }
- }
- onDestroy() {
- }
- }
|