Skip to content

Commit

Permalink
docs: Add more child actor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Sep 20, 2024
1 parent f70ae0d commit 0624968
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions site/docs/02-fundamentals/03-actors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions site/docs/10-physics/08-colliders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
})

````

0 comments on commit 0624968

Please sign in to comment.