【发布时间】:2020-04-06 13:54:42
【问题描述】:
我正在使用 Phaser 3 开发游戏,我需要使用某种可滚动面板,所以我选择使用 Rex UI(如果您知道任何替代方案,请告诉我。起初我想使用 Phaser-来自 npm 的列表视图,但它仅在移相器 2 中)。这些插件似乎没有太多文档。文档在此站点上:Notes of Phaser 3。
所以我有我的游戏配置,我正在像这样加载(过于简单):
import UIPlugin from '../plugins/ui-plugin.js';
const config = {
// ...
plugins: {
scene: [{
key: 'rexUI',
plugin: UIPlugin,
mapping: 'rexUI'
}]
}
// ...
};
const game = new Phaser.Game(config);
在一个场景中我尝试使用它:
export default class MyScene extends Phaser.Scene {
create() {
this.rexUI.add.scrollablePanel({
x: 0, y: 0,
width: innerWidth,
height: innerHeight/2,
scrollMode: 'horizontal',
panel: {
child: this.add.container().setSize(2 * innerWidth, innerHeight/2)
.add(this.itemImage(1))
.add(this.itemImage(2))
// ...
// (I'm actually using for-loop and save this container in a
// separate variable, but I'm over simplifying this snippet)
mask: false
},
slider: {
track: this.add.graphics({x: 0, y: innerHeight/2 + 10})
.fillRect(0, 0, innerWidth, 30).fillStyle(SOME_LIGHT_COLOR)
.setInteractive(
new Phaser.Geom.Rectangle(0, 0, innerWidth, 30),
Phaser.Geom.Rectangle.Contains
),
thumb: this.add.graphics({x: 0, y: innerWidth/2 + 10})
.fillRect(0, 0, 50, 30).fillStyle(SOME_DARK_COLOR)
.setInteractive(
new Phaser.Geom.Rectangle(0, 0, 50, 30),
Phaser.Geom.Rectangle.Contains
)
}
}).layout()
}
itemImage(n) {
return this.add.image((innerHeight/2 + 30) * (n-1), 0, 'item' + n)
.setDisplaySize(innerHeight/2, innerHeight/2)
}
}
有很多问题。首先使用上面的代码我得到了错误:
Uncaught TypeError: this.child.getAllChildren is not a function
at e.Xo [as resetChildPosition] (<anonymous>:1:205731)
at e.layout (<anonymous>:1:206243)
at e.layout (<anonymous>:1:126859)
at e.layout (<anonymous>:1:126859)
at e.value (<anonymous>:1:172299)
at MyScene.create (MyScene.js:117)
at initialize.create (phaser.min.js:1)
at initialize.loadComplete (phaser.min.js:1)
at initialize.h.emit (phaser.min.js:1)
at initialize.loadComplete (phaser.min.js:1)
如果我删除.layout(),错误就会消失。但是,滚动条上的拇指不在场景中的任何位置,我什至无法滚动容器。
文档没有说明 panel.child、scrolller.track 和 scroller.thumb 中应该包含的确切内容
有人可以帮我解决这个问题吗?
【问题讨论】:
-
我还没有使用那些插件,但是这里展示了 rex 的插件 codepen.io/rexrainbow 你是如何开始使用它进行编码的?因为也许最好看一下示例并复制一些代码
-
@nazimboudeffa 我只是按照您为可滚动面板链接的同一页面上的示例进行操作,并尝试将其更改为我的需要。我阅读了文档,仅此而已。我在网上没有找到关于这些插件的其他信息
-
好吧,我和你做的一模一样,所以让我也看看,如果我找到修复代码的方法,我会分享答案:)
标签: javascript plugins phaser-framework