GithubHelp home page GithubHelp logo

Query operators about bitecs HOT 2 CLOSED

thomasgauthier avatar thomasgauthier commented on June 2, 2024
Query operators

from bitecs.

Comments (2)

RemiMyrset avatar RemiMyrset commented on June 2, 2024

An example where I need to get tilemap tile. It has a sprite, integer position but not float position.

const query = defineQuery(
  [
    TilePositionComponent, // Vector2I
    SpriteComponent, // Sprite
    Not(PositionComponent), // Vector2
  ],
);
const entities = query(world);

Can be found in Query section of "Getting Started"
So you have the Not option, but not All and Any because that is frankly the default behavior(?).

from bitecs.

thomasgauthier avatar thomasgauthier commented on June 2, 2024

Thank you. I had missed the Not in the docs. All is indeed the default behavior.

Any does not seem to be implemented, but using TC39 Set Methods it can be done easily.


The following fictious code

defineQuery(
  [
    TilePositionComponent
    Any(SpriteComponent, Color)
  ],
);

can be implemented as

//set methods polyfill
import "core-js/features/set"

const tileQuery = defineQuery(
  [
    TilePositionComponent
  ],
);

const spriteQuery = defineQuery(
  [
    SpriteComponent,
  ],
);

const colorQuery = defineQuery(
  [
    Color
  ],
);

const entities = new Set(tileQuery(world))
  .intersects(
    new Set(spriteQuery(world))
    .union(new Set(colorQuery(world))
  );

from bitecs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.