diff --git a/site/docs/02-fundamentals/03-actors.mdx b/site/docs/02-fundamentals/03-actors.mdx index 7e6b434bd..8956bf251 100644 --- a/site/docs/02-fundamentals/03-actors.mdx +++ b/site/docs/02-fundamentals/03-actors.mdx @@ -72,6 +72,23 @@ class ShootemUpPlayer extends ex.Actor { Custom actors make it easy to hook into the actor lifecycle and encapsulate the actor's state better than a basic actor. + +## Child Actors + +Actors can be nested with within another, and all children have their transform (position, rotation, scale, z) relative to their parent. This is useful for a few a number of use cases. + +```typescript +const parent = new ex.Actor({...}); + +const child = new ex.Actor({...}); + +actor.addChild(child); +``` + +1. Paper doll assemblies - Moving a parent body actor and having child actor arms, legs, head, etc. pieces move. +2. Area Trigger Sensors - Adding invisible child actor to listen to collisions +3. Temporary attachment - Attaching a player to a moving platform + ## Actor lifecycle An actor has a basic lifecycle that dictates how it is initialized, updated, and drawn. Once an actor is part of a diff --git a/site/docs/10-physics/08-colliders.mdx b/site/docs/10-physics/08-colliders.mdx index 0d8927888..349c6ce63 100644 --- a/site/docs/10-physics/08-colliders.mdx +++ b/site/docs/10-physics/08-colliders.mdx @@ -112,3 +112,27 @@ const player = new ex.Actor({ collider: capsule }); ``` + +### Child Actor + +Another way of accomplishing complex collision logic is to add child actors with different colliders and handlers. + +This is can be useful for implementing area of effect collisions or sensors when objects get close to each other. + +For example: +```typescript +const player = new ex.Actor({...}); + +const sensor = new ex.Actor({ + radius: 100 +}); + +player.addChild(sensor); + +sensor.on('collisionstart', (evt) => { + if (evt.other !== player) { + console.log('something is within 100 pixels of player'); + } +}) + +```` \ No newline at end of file