123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- const HomeApi = require("../net/HomeApi");
- const DWTool = require("../utils/DWTool");
- cc.Class({
- extends: cc.Component,
- properties: {
-
- propSprite: cc.Sprite,
- nameRichText: cc.RichText,
- },
- init(buildingId, propData, pickupCallback) {
- this.buildingId = buildingId;
- DWTool.loadResSpriteFrame(`./item/${propData.id}`)
- .then((spriteFrame) => {
- this.propSprite.spriteFrame = spriteFrame;
- }).catch((err) => {
- console.log(err);
- });
- this.nameRichText.string = `<b><color=#ffffff>X${propData.count}</c></b>`;
- this.pickupCallback = pickupCallback;
- },
- updateProp(propData) {
- console.log(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, () => {
-
- this.pickupCallback();
- this.node.destroy();
- }, (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.coinNode.runAction(cc.sequence(upAction, downAction, callback));
- },
- });
|