当前位置: 首页 > 文档资料 > A-Frame 中文文档 >

pool

优质
小牛编辑
126浏览
2023-12-01

The pool component allows for object pooling. This gives us a reusable pool of entities to avoid creating and destroying the same kind of entities in dynamic scenes. Object pooling helps reduce GC pauses.

Example

For example, we may have a game with enemy entities that we want to reuse.

            
              <
                a-scene
                pool__enemy=
                "mixin: enemy; size : 10">
              </
                a-scene>
          
            
              varel = sceneEl.components.pool__enemy.requestEntity();
            sceneEl.components.pool__enemy.returnEntity(el);

Properties

PropertyDescriptionDefault Value
dynamicGrow the pool automatically if more entities are requested after reaching the size.false
mixinMixin used to initialize the entities of the pool.‘’
sizeNumber of preallocated entities in the pool.0

Methods

.requestEntity ()

Request one of the available entities in the pool.

.returnEntity (entityEl)

Relinquish an entity back to the pool.