Skip to content

How do you get a View with optional parameters? #14

Answered by player-03
NitroPlum asked this question in Q&A
Discussion options

You must be logged in to vote

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) {
		//...
	}
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NitroPlum
Comment options

Answer selected by NitroPlum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants