Sign in to follow this  
Thao Cao Minh

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

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 ={
    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 */                    
export default class Bullet extends Phaser.Physics.Arcade.Sprite {
    constructor(scene) {
        this.pivot = 0;
        this.power = 1;;
        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) {
    fire(xy) {
        this.originalY = y - 20;
        this.setPosition(xy - 20);
    setPivot(newPivot) {
        this.pivot = newPivot;

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.