collectible
Permet à un objet d'être collecté par un joueur
triggers on self
"picked""disapear"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
tag | identifiant des objets pouvant collecter | string | "player" |
offset | décalage de la position de l'animation | vec2 | vec2(0, -20) |
type | string | "collectible" | |
goesToInventory | boolean | false | |
autoDestroy | boolean | true |
example
collectible({ tag: "player", offset: vec2(0, -20), type: "collectible", goesToInventory: false, autoDestroy: true}),function collectible(p) { const param = { tag: "player", // identifiant des objets pouvant collecter offset: vec2(0, -20), // décalage de la position de l'animation type: "collectible", goesToInventory: false, autoDestroy: true, ...p } return { id: "collectible", add() { this.onCollide(param.tag, (obj) => { if (!this.is("respawn") || !this.beenHidden) { this.trigger("picked") obj.trigger("pick", { sprite: this.sprite, type: param.type, goesToInventory: param.goesToInventory }) if (param.autoDestroy) this.trigger("disapear") } }) this.on("disapear", () => { if (this.is("respawn")) this.hideFromScene() else destroy(this) }) }, }}