cocos creator 3.1.0 照官方给的demo进行编写 图片显示不出来
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
import * as fgui from "fairygui-cc"
@ccclass('Typescript')
export class Typescript extends Component {
private _view: fgui.GComponent = new fgui.GComponent;
private _bagWindow: fgui.Window = new BagWindow;
onLoad () {
debugger
fgui.GRoot.create();
fgui.UIPackage.loadPackage("Bag", this.onUILoaded.bind(this));
}
onUILoaded() {
this._view = fgui.UIPackage.createObject("Bag", "Main").asCom;
this._view.makeFullScreen();
fgui.GRoot.inst.addChild(this._view);
this._bagWindow = new BagWindow();
this._view.getChild("bagBtn").onClick(() => { this._bagWindow.show(); }, this);
}
}
class BagWindow extends fgui.Window {
public constructor() {
super();
}
protected onInit(): void {
debugger
this.contentPane = fgui.UIPackage.createObject("Bag", "BagWin").asCom;
this.center();
}
protected onShown(): void {
var list: fgui.GList = this.contentPane.getChild("list",fgui.GList);
list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
list.itemRenderer = this.renderListItem.bind(this);
list.setVirtual();
list.numItems = 45;
}
private renderListItem(index: number, obj: fgui.GObject): void {
debugger
obj.icon = "Icons/i" + Math.floor(Math.random() * 10);
obj.text = "" + Math.floor(Math.random() * 100);
}
private onClickItem(item: fgui.GObject): void {
this.contentPane.getChild("n11",fgui.GLoader).url = item.icon;
this.contentPane.getChild("n13").text = item.icon;
}
}
图片已经转换成spriteFrame类型了
没有找到相关结果
已邀请:
2 个回复
cs7685780
赞同来自:
谷主
赞同来自: