Html5 canvas 在画布/相位器3中创建表(优先级)
任何人都可以帮助在Phaser-3(优先级)/画布中创建表格 没有样式也可以。我只是想知道如何在Phaser-3(优先级)/画布中创建表。您可以尝试 在这里你可以找到一个 其他演示(滚动、固定宽度大小等…)可用 HTMLHtml5 canvas 在画布/相位器3中创建表(优先级),html5-canvas,phaser-framework,Html5 Canvas,Phaser Framework,任何人都可以帮助在Phaser-3(优先级)/画布中创建表格 没有样式也可以。我只是想知道如何在Phaser-3(优先级)/画布中创建表。您可以尝试 在这里你可以找到一个 其他演示(滚动、固定宽度大小等…)可用 HTML <footer><div id=version></div></footer> JS html, body { height: 100%; } body { margin: 0; padding: 0; ba
<footer><div id=version></div></footer>
JS
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
background: #222;
color: #eee;
font: caption;
}
#version {
position: absolute;
left: 5px;
top: 605px;
}
const Random = Phaser.Math.Between;
const COLOR_PRIMARY = 0x4e342e;
const COLOR_LIGHT = 0x7b5e57;
const COLOR_DARK = 0x260e04;
class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}
preload() {
this.load.scenePlugin({
key: 'rexuiplugin',
url: 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/plugins/dist/rexuiplugin.min.js',
sceneKey: 'rexUI'
});
}
create() {
this.print = this.add.text(0, 0, '');
var db = createDataBase(400);
var tabs = this.rexUI.add.tabs({
x: 400,
y: 300,
panel: this.rexUI.add.gridTable({
background: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_PRIMARY),
table: {
width: 250,
height: 400,
cellWidth: 120,
cellHeight: 60,
columns: 2,
mask: {
padding: 2,
},
},
slider: {
track: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_DARK),
thumb: this.rexUI.add.roundRectangle(0, 0, 0, 0, 13, COLOR_LIGHT),
},
// scroller: true,
createCellContainerCallback: function (cell) {
var scene = cell.scene,
width = cell.width,
height = cell.height,
item = cell.item,
index = cell.index;
return scene.rexUI.add.label({
width: width,
height: height,
background: scene.rexUI.add.roundRectangle(0, 0, 20, 20, 0).setStrokeStyle(2, COLOR_DARK),
icon: scene.rexUI.add.roundRectangle(0, 0, 20, 20, 10, item.color),
text: scene.add.text(0, 0, item.id),
space: {
icon: 10,
left: 15
}
});
},
}),
leftButtons: [
createButton(this, 2, 'AA'),
createButton(this, 2, 'BB'),
createButton(this, 2, 'CC'),
createButton(this, 2, 'DD'),
],
rightButtons: [
createButton(this, 0, '+'),
createButton(this, 0, '-'),
],
space: {
leftButtonsOffset: 20,
rightButtonsOffset: 30,
leftButton: 1,
},
})
.layout()
//.drawBounds(this.add.graphics(), 0xff0000);
tabs
.on('button.click', function (button, groupName, index) {
switch (groupName) {
case 'left':
// Highlight button
if (this._prevTypeButton) {
this._prevTypeButton.getElement('background').setFillStyle(COLOR_DARK)
}
button.getElement('background').setFillStyle(COLOR_PRIMARY);
this._prevTypeButton = button;
if (this._prevSortButton === undefined) {
return;
}
break;
case 'right':
// Highlight button
if (this._prevSortButton) {
this._prevSortButton.getElement('background').setFillStyle(COLOR_DARK)
}
button.getElement('background').setFillStyle(COLOR_PRIMARY);
this._prevSortButton = button;
if (this._prevTypeButton === undefined) {
return;
}
break;
}
// Load items into grid table
var items = db
.chain()
.find({
type: this._prevTypeButton.text
})
.simplesort('id', {
desc: (this._prevSortButton.text === '-') // sort descending
})
.data();
this.getElement('panel').setItems(items).scrollToTop();
}, tabs);
// Grid table
tabs.getElement('panel')
.on('cell.click', function (cellContainer, cellIndex) {
this.print.text += cellIndex + ': ' + cellContainer.text + '\n';
}, this)
.on('cell.over', function (cellContainer, cellIndex) {
cellContainer.getElement('background')
.setStrokeStyle(2, COLOR_LIGHT)
.setDepth(1);
}, this)
.on('cell.out', function (cellContainer, cellIndex) {
cellContainer.getElement('background')
.setStrokeStyle(2, COLOR_DARK)
.setDepth(0);
}, this);
tabs.emitButtonClick('left', 0).emitButtonClick('right', 0);
}
update() {}
}
var createDataBase = function (count) {
var TYPE = ['AA', 'BB', 'CC', 'DD'];
// Create the database
var db = new loki();
// Create a collection
var items = db.addCollection('items');
// Insert documents
for (var i = 0; i < count; i++) {
items.insert({
type: TYPE[i % 4],
id: i,
color: Random(0, 0xffffff)
});
}
return items;
};
var createButton = function (scene, direction, text) {
var radius;
switch (direction) {
case 0: // Right
radius = {
tr: 20,
br: 20
}
break;
case 2: // Left
radius = {
tl: 20,
bl: 20
}
break;
}
return scene.rexUI.add.label({
width: 50,
height:40,
background: scene.rexUI.add.roundRectangle(0, 0, 50, 50, radius, COLOR_DARK),
text: scene.add.text(0, 0, text, {
fontSize: '18pt'
}),
space: {
left: 10
}
});
}
var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scene: Demo
};
var game = new Phaser.Game(config);
const Random=Phaser.Math.Between;
常量COLOR_PRIMARY=0x4e342e;
恒色光=0x7b5e57;
const COLOR_DARK=0x260e04;
类演示扩展了Phaser.Scene{
构造函数(){
超级({
关键:“示例”
})
}
预加载(){
this.load.scenePlugin({
键:“rexuiplugin”,
网址:'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/plugins/dist/rexuiplugin.min.js',
sceneKey:“雷克苏”
});
}
创建(){
this.print=this.add.text(0,0',);
var db=createDataBase(400);
var tabs=this.rexUI.add.tabs({
x:400,
y:300,
面板:this.rexUI.add.gridTable({
背景:this.rexUI.add.roundRectangle(0,0,20,10,10,彩色),
表:{
宽度:250,
身高:400,
单元宽度:120,
牢房高度:60,
栏目:2,
遮罩:{
填充:2,
},
},
滑块:{
轨迹:this.rexUI.add.roundRectangle(0,0,20,10,10,颜色为深),
thumb:this.rexUI.add.roundRectangle(0,0,0,0,13,彩色光),
},
//卷轴:是的,
createCellContainerCallback:函数(单元格){
var scene=cell.scene,
宽度=单元格宽度,
高度=单元格高度,
item=cell.item,
index=cell.index;
return scene.rexUI.add.label({
宽度:宽度,
高度:高度,,
背景:scene.rexUI.add.roundRectangle(0,0,20,20,0).setStrokeStyle(2,颜色为深),
图标:scene.rexUI.add.roundRectangle(0,0,20,20,10,item.color),
text:scene.add.text(0,0,item.id),
空间:{
图标:10,
左:15
}
});
},
}),
左按钮:[
createButton(这个,2,'AA'),
createButton(这个,2,'BB'),
createButton(这个,2,'CC'),
createButton(这个,2,'DD'),
],
右键按钮:[
createButton(这个,0,“+”),
createButton(这个,0,“-”),
],
空间:{
leftButtonsOffset:20,
右按钮偏移量:30,
左键:1,
},
})
.layout()
//.drawBounds(this.add.graphics(),0xff0000);
标签
.on('button.click',函数(按钮、组名、索引){
开关(组名){
案例“左”:
//突出显示按钮
如果(此按钮){
此._prevTypeButton.getElement('background').setFillStyle(颜色为深)
}
button.getElement('background').setFillStyle(主颜色);
这个。_prevTypeButton=按钮;
如果(此._PrevisortButton==未定义){
返回;
}
打破
案例“正确”:
//突出显示按钮
如果(此按钮){
此.u previsortButton.getElement('background').setFillStyle(颜色为深)
}
button.getElement('background').setFillStyle(主颜色);
此按钮。_previsortbutton=按钮;
如果(此._prevTypeButton==未定义){
返回;
}
打破
}
//将项目加载到网格表中
变量项=db
.chain()
.找到({
类型:this.\u prevTypeButton.text
})
.simplesort('id'{
desc:(this.\u previsortbutton.text=='-')//降序排序
})
.data();
this.getElement('panel').setItems(items).scrollToTop();
},标签页);
//网格表
tabs.getElement(“面板”)
.on('cell.click',函数(cellContainer,cellIndex){
this.print.text+=cellIndex+':'+cellContainer.text+'\n';
},本页)
.on('cell.over',函数(cellContainer,cellIndex){
cellContainer.getElement('background')
.setStrokeStyle(2,彩色灯)
.设置深度(1);
},本页)
.on('cell.out',函数(cellContainer,cellIndex){
cellContainer.getElement('background')
.setStrokeStyle(2,深色)
.setDepth(0);
},这个);
tabs.emitButton单击('left',0).emitB