Laya场景之间传递数据

  1. 本地存储LocalStorage,可全局读取调用,比较方便
    //旧页面
    LocalStorage.setItem("XXX", XXX);
    
    
    //新页面
    XXX = LocalStorage.getItem("XXX");

  2. Scene.open场景参数,单一传递到新场景,一次性调用
    旧场景
    Laya.Scene.open("GameMain/某场景.scene", true, xxx)
    
    
    //新场景
    		public function onOpened(args: Object) {
    			xxx = args
    
    		}
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Laya 中使用 ListView 实现数据高度不同的列表,可以通过 `itemRender` 方法来实现。 首先,我们需要在 ListView 的属性中设置 `renderHandler` 方法,该方法会在 ListView 中的每个 item 被创建时调用。在 `renderHandler` 方法中,我们可以创建 item 的视图,并设置 item 中的数据。具体代码如下: ```javascript // 创建 ListView var list = new Laya.List(); list.width = 300; list.height = 400; list.itemRender = Item; list.renderHandler = new Laya.Handler(this, onRender); this.addChild(list); // renderHandler 方法 function onRender(item, index) { // 设置 item 的数据 item.setData(data[index]); // 设置 item 的高度 item.height = item.getData().height; } // Item 类 var Item = (function(_super) { function Item() { Item.__super.call(this); this.init(); } Laya.class(Item, "Item", _super); Item.prototype.init = function() { // 创建 item 的视图 // ... }; Item.prototype.setData = function(data) { // 设置 item 中的数据 // ... }; Item.prototype.getData = function() { // 获取 item 中的数据 // ... }; return Item; })(Laya.Box); ``` 在上面的代码中,`Item` 类代表 ListView 中的每个 item,我们在 `init` 方法中创建 item 的视图,在 `setData` 方法中设置 item 中的数据,在 `getData` 方法中获取 item 中的数据。 在 `onRender` 方法中,我们根据数据的高度设置 item 的高度,这样 ListView 中的每个 item 的高度就会不同。 另外,我们还需要在 ListView 的属性中设置 `scrollBar` 为 `null`,这样 ListView 中就不会出现滚动条。如果需要滚动条,可以使用 Laya 的 ScrollBar 组件来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值