-
Is there a way to use the View syntax to get a view with optional parameters? I assume so considering you can do it as part of a function declaration. The below doesn't work but I'd assume something like that is possible.
|
Beta Was this translation helpful? Give feedback.
Answered by
player-03
Dec 19, 2023
Replies: 1 comment 1 reply
-
There's no syntax sugar for that, no. Under the hood, optional components aren't in the view at all. //`Sprite` is an optional component, since it isn't in the view.
private var needsGizmo:View<Position> = getLinkedView(Position); The view gives you a reference to the entity, and you can use that to check for any component you like. needsGizmo.iter(function(entity:Entity, position:Position) {
var sprite:Null<Sprite> = entity.get(Sprite);
if(sprite != null) {
//...
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
NitroPlum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's no syntax sugar for that, no. Under the hood, optional components aren't in the view at all.
The view gives you a reference to the entity, and you can use that to check for any component you like.