import UtilTool from “…/…/…/…/…/Script/framework/utils/UtilTool”;
import WxUserData from “…/…/…/…/…/Script/data/WxUserData”;
import SystemData from “…/…/…/…/…/Script/data/SystemData”;
// Learn TypeScript:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class ChildCameraNode extends cc.Component {
@property(cc.Node)
result_node: cc.Node = null;
@property(cc.Node)
zui_context: cc.Node = null;
@property(cc.Node)
zui_context_z: cc.Node = null;
@property(cc.Camera)
camera: cc.Camera = null;
private _RadomAnim: boolean = false;
// LIFE-CYCLE CALLBACKS:
onLoad() {
if (SystemData.Model.indexOf("iPhone") != -1 && SystemData.Model.indexOf("6") != -1) {
console.warn("iiphone6 ????????");
return;
}
this.camera.enabled = true;
let renderTexture = new cc.RenderTexture();
let gl = cc.game._renderContext;
renderTexture.initWithSize(cc.view.getViewportRect().width, cc.view.getViewportRect().height, gl.STENCIL_INDEX8);
// ßrenderTexture.setPremultiplyAlpha(true);
let spritef = new cc.SpriteFrame();
spritef.setTexture(renderTexture);
this.zui_context.getComponent(cc.Sprite).spriteFrame = spritef;
this.zui_context_z.getComponent(cc.Sprite).spriteFrame = spritef;
this.camera.targetTexture = renderTexture;
this.camera.enabled = false;
//this.zui_context.x = 10;
}
start() {
}
startAnim() {
this.camera.enabled = true;
this._RadomAnim = true;
this.RadomAnim();
}
stopAnim() {
this.camera.enabled = false;
this._RadomAnim = false;
this.zui_context.stopAllActions();
this.zui_context_z.stopAllActions();
let action = cc.spawn(
cc.moveTo(0.5, 0, 0).easing(cc.easeQuadraticActionOut()),
cc.fadeTo(0.5, 0).easing(cc.easeInOut(0.5))
);
let action_z = cc.spawn(
cc.moveTo(0.5, 0, 0).easing(cc.easeQuadraticActionOut()),
cc.fadeTo(0.5, 0).easing(cc.easeInOut(0.5))
);
this.zui_context.runAction(action);
this.zui_context_z.runAction(action_z);
}
RadomAnim() {
//console.log("startanim",this._RadomAnim);
if (this._RadomAnim) {
let x = UtilTool.random(6, 9);
let y = UtilTool.random(6, 9);
// let o = UtilTool.random(30, 50);
// let o_z = UtilTool.random(10, 50);
let o = UtilTool.random(66, 150);
let o_z = UtilTool.random(66, 150);
let action = cc.sequence(
cc.spawn(
cc.moveTo(1, x, y).easing(cc.easeQuadraticActionOut()),
cc.fadeTo(1, o).easing(cc.easeInOut(1))
),
cc.delayTime(0.3),
cc.spawn(
cc.moveTo(0.5, 0, 0).easing(cc.easeQuadraticActionIn()),
cc.fadeTo(0.5, 0).easing(cc.easeInOut(0.5))
),
cc.delayTime(4),
cc.callFunc(this.RadomAnim, this)
);
let action_z = cc.sequence(
cc.spawn(
cc.moveTo(1, -x, -y).easing(cc.easeQuadraticActionOut()),
cc.fadeTo(1, o_z).easing(cc.easeInOut(1))
),
cc.delayTime(0.3),
cc.spawn(
cc.moveTo(0.5, 0, 0).easing(cc.easeQuadraticActionIn()),
cc.fadeTo(0.5, 0).easing(cc.easeInOut(0.5))
),
// cc.delayTime(4),
// cc.callFunc(this.RadomAnim, this)
);
this.zui_context.runAction(action);
this.zui_context_z.runAction(action_z);
}
}
update(dt) {
if (SystemData.Model.indexOf("iPhone") != -1 && SystemData.Model.indexOf("6") != -1) {
return;
}
//console.log(WxUserData.zui.now / WxUserData.zui.up * 100,this._RadomAnim);
if (this._RadomAnim) {
//?????????????????
if (this.result_node.active) {
this.stopAnim();
} else {
let bf = WxUserData.zui.now / WxUserData.zui.up * 100;
if (bf >= 80) {
return;
} else {
this.stopAnim();
}
}
} else {
let bf = WxUserData.zui.now / WxUserData.zui.up * 100;
if (bf >= 80) {
if (!this.result_node.active) {
this.startAnim();
} else {
return;
}
} else {
return;
}
}
}
}