Aller au contenu

Ajouter un composant

component.js
function customComponent(p) {
const param = {
// add you parameters here
...p
}
return {
// runs when the object is declared
add() {
},
// runs on every frame
update() {
},
}
}
config.js
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(),
],
},
};
component.js
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() {
},
}
}
config.js
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(),
],
},
};
component.js
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() {
},
}
}