egret 把所有的元素加入滑动框

egret 把所有的元素加入滑动框

```this.sv()//核心代码


private spr: egret.Sprite

private scrollView: egret.ScrollView

private sv() {

var arr = []

var groupChild = this.numChildren;

// console.log(groupChild);

for (var k = 0; k < groupChild; k++) {

// if(k==13){

// k+=2

// }

if (!this.getChildAt(k)) continue;

var child = this.getChildAt(k)

// this.spr.addChild(child)

arr.push(child)

// console.log(child, k);

}

this.spr = new egret.Sprite()

for (let i = 0; i < arr.length; i++) {

this.spr.addChild(arr[i])

}

this.spr.alpha = 1

this.addChild(this.spr)

this.scrollView = new egret.ScrollView();

this.scrollView.height = egret.MainContext.instance.stage.stageHeight;

this.scrollView.width = 640;

this.scrollView.horizontalScrollPolicy = "off";

//设置滚动内容

this.scrollView.bounces = false//回弹

this.scrollView.scrollSpeed = .1

this.scrollView.setContent(this.spr);

this.addChild(this.scrollView);

}```

查看H5案列

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.纹理集实际上就是将一些零碎的小图放到一张大图当中。游戏中也经常使用到纹理集。使用纹理集的好处很多,我们通过将大...
    别人家的程序员阅读 12,517评论 1 21
  • 官方文档 微信小游戏快速上手egret微信小游戏开发指南菜鸟|Egret微信小游戏好友排行榜教程小程序与小游戏获取...
    Coder_Cat阅读 4,977评论 0 0
  • 随着微信小游戏的突起,一些游戏引擎也越来越火了,目前支持小游戏的游戏引擎就那么几个:Cocos、Egret、Lay...
    向阳花木_5ad7阅读 4,949评论 0 0
  • 1、js代码运行顺序: 1)、先执行script中的所有同步代码,过程中把所有异步任务压进它们各自的队列(假设维护...
    易_9ac1阅读 4,351评论 0 0
  • 前端面试题的简单整理,都只是大概回答,具体某些问题的具体理解后续会补上。 前端页面有哪三层构成,分别是什么?作用是...
    李欢li阅读 3,332评论 0 2