12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- cc.Class({
- extends: cc.Component,
- name: "GameOverRank",
- properties: {
- backSprite: cc.Node,
- rankLabel: cc.Label,
- avatarImgSprite: cc.Sprite,
- nickLabel: cc.Label,
- topScoreLabel: cc.Label,
- },
- start() {
- },
- init: function (rank, data,isPlayer) {
- let avatarUrl = data.avatarUrl;
- // let nick = data.nickname.length <= 10 ? data.nickname : data.nickname.substr(0, 10) + "...";
- let nick = data.nickname;
- let grade = data.KVDataList.length != 0 ? data.KVDataList[0].value : 0;
- if (rank % 2 == 0) {
- this.backSprite.color = new cc.Color(55, 55, 55, 255);
- }
- if (isPlayer) {
- this.rankLabel.node.color = new cc.Color(0, 255, 0, 255);
- }
- this.rankLabel.string = (rank + 1).toString();
- this.createImage(avatarUrl);
- this.nickLabel.string = nick;
- this.topScoreLabel.string = grade.toString();
- },
- createImage(avatarUrl) {
- if (window.wx != undefined) {
- try {
- let image = wx.createImage();
- image.onload = () => {
- try {
- let texture = new cc.Texture2D();
- texture.initWithElement(image);
- texture.handleLoadedTexture();
- this.avatarImgSprite.spriteFrame = new cc.SpriteFrame(texture);
- } catch (e) {
- cc.log(e);
- this.avatarImgSprite.node.active = false;
- }
- };
- image.src = avatarUrl;
- }catch (e) {
- cc.log(e);
- this.avatarImgSprite.node.active = false;
- }
- } else {
- cc.loader.load({
- url: avatarUrl, type: 'jpg'
- }, (err, texture) => {
- this.avatarImgSprite.spriteFrame = new cc.SpriteFrame(texture);
- });
- }
- }
- });
|