Ajouter un composant
Créer un composant
Section intitulée « Créer un composant »function customComponent(p) { const param = { // add you parameters here ...p } return { // runs when the object is declared add() { }, // runs on every frame update() { }, }}Utiliser le composant
Section intitulée « Utiliser le composant »const LEVEL_CONFIG = {
tileWidth: 64, tileHeight: 64, backgroundColor: "afe1ff", gravity: 3200,
tiles: {
"#": () => [ // player 1 customComponent(), sprite("bean"), platformerController(), alive(), opacity(), scale(), health(1, 4), area(), anchor("bot"), body(), respawn(), falling(), coloring(), animator(), ],
},};Créer des paramètres
Section intitulée « Créer des paramètres »function customComponent(p) { const param = { customParameter: "default value", ...p } return { // runs when the object is declared add() { debug.log( param.customParameter ) }, // runs on every frame update() { }, }}Utiliser le composant avec des paramètres
Section intitulée « Utiliser le composant avec des paramètres »const LEVEL_CONFIG = {
tileWidth: 64, tileHeight: 64, backgroundColor: "afe1ff", gravity: 3200,
tiles: {
"#": () => [ // player 1 customComponent({customParameter: 'specified'}), sprite("bean"), platformerController(), alive(), opacity(), scale(), health(1, 4), area(), anchor("bot"), body(), respawn(), falling(), coloring(), animator(), ],
},};Créer des variables publiques
Section intitulée « Créer des variables publiques »function customComponent(p) { const param = { ...p } return { customPublicValue : "default value" , // runs when the object is declared add() { debug.log( param.customPublicValue ); }, // runs on every frame update() { }, }}