Jump to content

Rectangle in group.


smoky
 Share

Recommended Posts

I have problem with phaser.js, i use this framework from yesterday, and IMO is very good, but i dont know how to render basic shapes (ex. Rectangle) in Group, i tryed this, but didn't work. Basic example with group and rectangle is enough for me. Thx in advance and greetings from Poland. 

class Piano
{
    constructor() {
        this.keys = new Object();
        this.keys_grp = game.add.group();
        this.keys_pad = 'qwerty';
       
        for(let i=0;i<this.keys_pad.length;++i) {

            this.keys[this.keys_pad[i]] =
                new Phaser.Rectangle(i*15, 0,
                                     10, 20);

            this.keys_grp.add(0,0,this.keys['q']);

        }
    }

    display() {

    }
}

I got this error:

Uncaught Error: 0addChildAt: The index [{Rectangle (x=0 y=0 width=10 height=20 empty=false)}] supplied is out of bounds 0
    at Phaser.Group.PIXI.DisplayObjectContainer.addChildAt.....

Smoky.

Link to comment
Share on other sites

Hi smoky, the correct arguments for Group#add are

group.add(child, silent, index)

which is why you're getting the "out of bounds" error, but I don't think you can add Phaser.Rectangle to a group since it's not a display object.

Try creating a Phaser.Graphics object, draw a rectangle on that, and add the graphics to the group.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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