multiplayerCamera
Permet à la camera de suivre plusieurs objets à la fois
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
tag | string | 'player' | |
posAnimDelay | number | 0.1 | |
zoomAnimDelay | number | 0.2 | |
distanceMin | number | 200 | |
amplitudeZoom | number | 0.0008 | |
zoomReductioLimit | number | 0.4 | |
screenRatio | number | 600 | |
posAnimEasing | unknown | easings.linear | |
zoomAnimEasing | unknown | easings.linear |
example
multiplayerCamera({ tag: 'player', posAnimDelay: 0.1, zoomAnimDelay: 0.2, distanceMin: 200, amplitudeZoom: 0.0008, zoomReductioLimit: 0.4, screenRatio: 600, posAnimEasing: "easings.linear", zoomAnimEasing: "easings.linear"}),function multiplayerCamera(p) { const param = { tag: 'player', posAnimDelay: 0.1, zoomAnimDelay: 0.2, distanceMin: 200, amplitudeZoom: 0.0008, zoomReductioLimit: 0.4, screenRatio: 600, posAnimEasing: easings.linear, zoomAnimEasing: easings.linear, ...p, }; return { id: 'camera', pos: null, zoom: null, targets: [], add() { this.targets = get(param.tag, { recursive: true, liveUpdate: true, }); /* for (const e of this.targets) e.onPhysicsResolve(() => this.setCameraPos()); */ }, update() { if (this.targets.length > 0) { let min = vec2(this.targets[0].pos); let max = vec2(this.targets[0].pos); let sum = vec2(0, 0); let targetsLength = 0; for (const p of this.targets) { if (p.isAlive) { targetsLength++; sum = sum.add(p.pos); min.x = Math.min(p.pos.x, min.x); max.x = Math.max(p.pos.x, max.x); min.y = Math.min(p.pos.y, min.y); max.y = Math.max(p.pos.y, max.y); } } const dist = Math.max(min.dist(max) - param.distanceMin, 0); const zoom = Math.max( 1 - dist * param.amplitudeZoom, param.zoomReductioLimit ); const scale = 1 / targetsLength; const tragetPos = vec2(sum).scale(scale); if (this.pos == undefined) this.pos = tragetPos; if (this.zoom == undefined) this.zoom = zoom; if (targetsLength > 0) { tween( this.pos, tragetPos, param.posAnimDelay, (p) => (this.pos = p), param.posAnimEasing ); tween( this.zoom, zoom, param.zoomAnimDelay, (p) => (this.zoom = p), param.zoomAnimEasing ); setCamPos(this.pos); setCamScale((this.zoom * height()) / param.screenRatio); } } }, };}