123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- const HomeApi = require("../net/HomeApi");
- const DWTool = require("../utils/DWTool");
- const itemList = require('../data/item');
- const GameModule = require("../utils/GameModule");
- cc.Class({
- extends: cc.Component,
- properties: {
-
- propSprite: cc.Sprite,
- nameRichText: cc.RichText,
- },
- init(buildingId, propData, pickupCallback) {
- this.buildingId = buildingId;
- // 根据道具id获取道具数据
- this.propData = Object.assign(propData, itemList.find(n => {
- return n.id == propData.id
- }))
- console.log(this.propData);
- DWTool.loadResSpriteFrame(`./item/${this.propData.picId}`)
- .then((spriteFrame) => {
- this.propSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- this.nameRichText.string = `<b><color=#ffffff>X${this.propData.count}</c></b>`;
- this.pickupCallback = pickupCallback;
- },
- updateProp(propData) {
- this.nameRichText.string = `<b><color=#ffffff>X${propData.count}</c></b>`;
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- // this.node.y = -26;
- // this.node.x = 150;
- this.node.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
- // 上报领取
- HomeApi.itemCollect(this.buildingId, () => {
- // 钻石
- if(this.propData.id == 10002) {
- GameModule.userInfo.updateUserRes({
- diamond: this.propData.count
- })
- }
- // 艺人券
- if(this.propData.id == 10003) {
- GameModule.userInfo.updateUserRes({
- ticket: this.propData.count
- })
- }
-
- this.pickupCallback();
- let showFrame = this.propSprite.spriteFrame;
- let showText = `${this.propData.name} x ${this.propData.count}`
- this.pickupCallback(showFrame, showText);
-
- }, (err) => {
- console.log(err);
- })
- }, 1000, true), this);
- },
- showAnimation() {
- if (this.isPlaying) { return; }
- this.node.stopAllActions();
- this.node.active = true;
- this.isPlayed = true;
- this.isPlaying = true;
- let jumpHeight = 175;
- let duration = 0.3;
- let animationArray = [];
- let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
- let moveAction2 = cc.moveBy(duration, 0, -95).easing(cc.easeCubicActionIn());
- animationArray.push(moveAction1);
- animationArray.push(moveAction2);
- while(jumpHeight > 0.1) {
- jumpHeight = jumpHeight - (jumpHeight / 3);
- duration = duration - (duration / 3);
- let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
- let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
- animationArray.push(upAction);
- animationArray.push(downAction);
- }
- let callback = cc.callFunc(() => {
- this.isPlaying = false;
- });
- animationArray.push(callback);
- this.node.runAction(cc.sequence(animationArray));
- },
- updateAnimation() {
- if (this.isPlaying) { return; }
- this.node.active = true
- this.node.y = -28;
- this.node.stopAllActions();
-
- this.isPlaying = true;
- let upAction = cc.moveBy(0.1, 0, 30);
- let downAction = cc.moveBy(0.1, 0, -30);
- let callback = cc.callFunc(() => {
- this.isPlaying = false;
- });
- this.propSprite.node.runAction(cc.sequence(upAction, downAction, callback));
- },
- });
|