handSprite
permet d'afficher un objet devant le personnage
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
sprite | string | "gun" | |
handDistance | number | 40 | |
jointPos | vec2 | vec2(0, 0) | |
anchor | vec2 | vec2(0, 0) | |
flipY | boolean | true | |
rotation | number | 0 | |
rotate | boolean | true | |
aim | boolean | true | |
hiddenOnStart | boolean | false |
example
handSprite({ sprite: "gun", handDistance: 40, jointPos: vec2(0, 0), anchor: vec2(0, 0), flipY: true, rotation: 0, rotate: true, aim: true, hiddenOnStart: false}),function handSprite(p) { const param = { sprite: "gun", handDistance: 40, jointPos: vec2(0, 0), anchor: vec2(0, 0), flipY: true, rotation: 0, rotate: true, aim: true, hiddenOnStart: false, ...p } return { id: "hand", hand: null, add() { let angle = 0 this.hand = this.add([ sprite(param.sprite, { width: param.width }), pos(param.jointPos.add(Vec2.fromAngle(param.rotation).scale(param.handDistance))), anchor(param.anchor), opacity(), rotate(param.rotation), ]) if (param.aim) this.on("aiming", (p) => { this.hand.pos = param.jointPos.add(Vec2.fromAngle(p).scale(param.handDistance)) this.hand.angle = p + param.rotation - ((this.is("rotate")) ? this.angle : 0) this.hand.flipY = Math.abs(p) > 90 }) this.hand.hidden = param.hiddenOnStart this.on("grab", (p) => { this.trigger("grab catch", { dist: this.hand.pos.add(p.origin.sub(this.pos.add(this.hand.pos))) }) this.hand.hidden = false; this.hand.sprite = p.item.sprite this.hand.width = p.item.width }) this.on("respawn", (p) => { this.hand.hidden = param.hiddenOnStart; this.hand.sprite = param.sprite }) this.on("drop item", () => { this.hand.hidden = true; }) }, }}