Sun_moves/assets/Script/Load.ts
2024-05-28 11:38:16 +08:00

96 lines
2.6 KiB
TypeScript

// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property, requireComponent} = cc._decorator;
import GameData from "./GameData";
import HttpUtil from "./crypto/serverAPI";
import Rq from "./crypto/serverAPI";
// import { apiSign } from "./crypto/sign";
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
start () {
GameData._instance.GM_INFO.userId = this.getUserId();
if(GameData._instance.GM_INFO.userId == null){
let url = "http://api.sparkus.cn/api/user/auth/login?domain=hui32579WdYPsgYq&callback=http://train.sparkus.cn/test/Sun_moves/";
window.location.href = url;
}
else{
GameData._instance.GM_INFO.userId = parseInt(GameData._instance.GM_INFO.userId);
}
}
createTexture(){
let url = "http://static.sparkus.cn/shoot-sun/assets/resources/native/7a/7a8b41ad-9425-44e2-8f55-7740f12b0e0a.jpg";
cc.assetManager.loadRemote(url, (err, texture:cc.Texture2D) => {
console.log(err,texture)
if(texture){
var sprite = this.node.getChildByName("icon").getComponent(cc.Sprite);
sprite.spriteFrame = new cc.SpriteFrame(texture);
}
})
}
private getUserId() {
let pathStr = window.location.search;
let arr=pathStr.split("&");
if (pathStr.length>= 0&&arr.length>0) {
let arr2=[];
arr.map(item=>{
arr2.push(item.split("=")[1])
})
GameData._instance.GM_INFO.userId = arr2[0] + "";
return arr2[0];
} else {
return null
}
}
startGame(){
GameData._instance.GM_INFO.custom = 0;
cc.director.loadScene("GuideScene");
}
clickBtn(event,data){
GameData._instance.GM_INFO.custom = parseInt(data);
cc.director.loadScene("GameScene");
}
openLevel(){
this.node.getChildByName("Level").active = true;
}
closeBtn(){
this.node.getChildByName("Level").active = false;
}
back(data){
// debugger;
}
openBtn(){
GameData._instance.GM_INFO.custom = 0;
cc.director.loadScene("GuideScene");
}
openRank(){
cc.director.loadScene("RankScene");
}
// update (dt) {}
}