Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为Phaser 3池创建对象副本_Javascript_Phaser Framework_Pooling - Fatal编程技术网

Javascript 为Phaser 3池创建对象副本

Javascript 为Phaser 3池创建对象副本,javascript,phaser-framework,pooling,Javascript,Phaser Framework,Pooling,我目前正在Phaser3中制作一个塔防游戏,我需要一些帮助来重构我的代码以实现一个通用池。现在我有几个不同的池,我手动填充 for (let i = 0; i < 10; i++) { let basicEnem = new Enemy(this, 'enemySprite', elements.FIRE,400, 400, 150, 20); this.EnemyPool.add(basicEnem); this.EnemyPool.killAndHi

我目前正在Phaser3中制作一个塔防游戏,我需要一些帮助来重构我的代码以实现一个通用池。现在我有几个不同的池,我手动填充

for (let i = 0; i < 10; i++) {
      let basicEnem = new Enemy(this, 'enemySprite', elements.FIRE,400, 400, 150, 20);
      this.EnemyPool.add(basicEnem);
      this.EnemyPool.killAndHide(basicEnem);
    }
for (let i = 0; i < 200; i++) {
      let bull = new Bullet(this, 50, 400, 90, 10, 100, elements.FIRE, 'bulletSprite');
      this.BulletPool.add(bull);
      this.BUlletPool.killAndHide(bull);
    }
for(设i=0;i<10;i++){
让basicEnem=新敌人(这是“敌人之旅”,元素。开火,400,400,150,20);
this.EnemyPool.add(basicEnem);
这个.EnemyPool.killAndHide(basicEnem);
}
for(设i=0;i<200;i++){
让公牛=新子弹(这个,504009010100,elements.FIRE,'bulletSprite');
this.BulletPool.add(bull);
这个。子弹池。killAndHide(公牛);
}
我想创建一个Pool类,它通过一个实例创建多个副本。我曾考虑过深度克隆,但有人告诉我,它不适用于类方法

export default class Pool extends Phaser.GameObjects.Group {
    constructor(scene, isPhysical,poolItem,baseSize) {
        super();
        this._scene = scene;
        this._group;
        if (isPhysical)
            this._group = this._scene.physics.add.group();
        else
            this._group = this._scene.add.group();
        for(let i = 0;i<baseSize;i++){
            //a copy of any instance of poolItem class
        }
    }
导出默认类池扩展Phaser.GameObjects.Group{
构造函数(场景、iPhysical、池项、baseSize){
超级();
这个._scene=场景;
本组;
if(物理)
this._group=this._scene.physics.add.group();
其他的
this._group=this._scene.add.group();
for(设i=0;i