Skip to content

Commit

Permalink
fix: [#3083] Actors inherit opacity from parents
Browse files Browse the repository at this point in the history
Closes #3083
  • Loading branch information
eonarheim committed Sep 12, 2024
1 parent 588d0c1 commit b095216
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Child `ex.Actor` inherits opacity of parents
- `ex.Engine.timeScale` values of 0 are now supported
- `ex.Trigger` now supports all valid actor constructor parameters from `ex.ActorArgs` in addition to `ex.TriggerOptions`
- `ex.Gif` can now handle default embedded GIF frame timings
Expand Down
11 changes: 10 additions & 1 deletion src/engine/Graphics/GraphicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export class GraphicsSystem extends System {
}
entity.events.emit('predraw', new PreDrawEvent(this._graphicsContext, elapsedMs, entity));

this._graphicsContext.opacity *= graphics.opacity;
// this._graphicsContext.opacity *= graphics.opacity;
this._applyOpacity(entity);

// Draw the graphics component
this._drawGraphicsComponent(graphics, transform);
Expand Down Expand Up @@ -269,4 +270,12 @@ export class GraphicsSystem extends System {
}
}
}

private _applyOpacity(entity: Entity): void {
const ancestors = entity.getAncestors();
for (const ancestor of ancestors) {
const maybeGraphics = ancestor?.get(GraphicsComponent);
this._graphicsContext.opacity *= maybeGraphics?.opacity ?? 1;
}
}
}

0 comments on commit b095216

Please sign in to comment.