laya自定义滚动条
滚动条不是纯色, 不好缩放, 可以使用蒙版自己移动图片
testBar是滚动条, 使用jdt.png, jdt$bar是个透明图片. bar2蓝色的图, 使用barMask做蒙版
const { regClass, property } = Laya;@regClass() export class Main extends Laya.Script {private _testBar!: Laya.ProgressBar;private _barMask!: Laya.Sprite;private _dog!: Laya.Sprite;onAwake(): void {this._testBar = this.owner.getChildByName("testBar") as Laya.ProgressBar;this._barMask = this._testBar.getChildByName("bar2").getChildByName("barMask") as Laya.Sprite;this._dog = this._testBar.getChildByName("dog") as Laya.Sprite;this._testBar.on(Laya.Event.CHANGE, this, this.onTestBarChange);}onStart() {console.log("Game start");Laya.timer.loop(100, this, this.onUpdateBar);}onUpdateBar(): void {this._testBar.value += 0.01;if (this._testBar.value >= 1) {this._testBar.value = 0;}}private onTestBarChange(): void {this._barMask.x = (this._testBar.value - 1) * this._testBar.width;this._dog.x = this._testBar.width * this._testBar.value;} }
Laya 3.0.10 示例下载
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/935102.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!