Jump to content

Add parameter to a child's contructor while create its group.


Thao Cao Minh
 Share

Recommended Posts

I have a problem while create a group, that i want to add parameter to the children of the group. I logged the group, it showed that it was a list of children. But the next line i tried to interate them to set property for its child, the length of list = 0; I don't know how to deal with this problem, so...

Thank you for reading this.

This is my code:

// this is in the GameScene create group function
    var bullets = context.add.group({
        classTypeBullet,
        runChildUpdatetrue,
        maxSize40
    });
    console.log(bullets.getChildren());                                                                   /* The log show that have a mount of child in it */
    bullets.getChildren().forEach(element => {                                       /* The none of children so the bullets.length = 0, nothing change to the pivot */                    
        element.setPivot(pivot);
    });
 
export default class Bullet extends Phaser.Physics.Arcade.Sprite {
    constructor(scene) {
        super(scene00'dan1');
        this.pivot = 0;
        this.power = 1;
        scene.physics.world.enable(this);
        this.speed = Phaser.Math.GetSpeed(4001);  // 400px/1s
    }
    preload() { }
    create() { }
    update(timedelta) {
        this.y -= this.speed * delta;
        this.x -= this.pivot * (this.speed / this.originalY* delta;
        if (this.y < -50) {
            this.destroy(true);
        };
    }
    fire(xy) {
        this.originalY = y - 20;
        this.setPosition(xy - 20);
        this.setActive(true);
        this.setVisible(true);
    }
    setPivot(newPivot) {
        this.pivot = newPivot;
    }
    
}
Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...