1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- cc.Class({
- extends: cc.Component,
- name: "RankItem",
- properties: {
- backSprite: cc.Node,
- rankLabel: cc.Label,
- avatarImgSprite: cc.Sprite,
- nickLabel: cc.Label,
- topScoreLabel: cc.Label,
- },
- start() {
- },
- init: function (rank, data) {
- 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;
-
- this.rankLabel.string = (rank + 1).toString();
- this.createImage(avatarUrl);
- this.nickLabel.string = nick;
- this.topScoreLabel.string = grade.toString();
- },
- createImage(avatarUrl) {
- 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;
- }
- }
- });
|