mattcolman / phaser-list-view

List view class for Phaser. Great for high scoreboards.
http://mattcolman.com/labs/phaser-list-view/index.html
MIT License
116 stars 21 forks source link

Publish a list of sprites #27

Open Kababaer opened 5 years ago

Kababaer commented 5 years ago

Hi,

I cannot seem to get it to run. I have a list of sprites which I want to be displayed vertical and the user should be able to scroll through vertically.

var startX = this.fHeader.x;
    var startY = this.fHeader.y + this.fHeader.height;

    var sprites = [];
    this.highscores.forEach(function(highscore) {
        var sprite = game.add.sprite(startX, startY, 'spriteKey');
        startY += sprite.height;
        sprites.push(sprite);
    }, this);

    var bounds = new Phaser.Rectangle(0, 0, 1000, 2000);
    var options = {
        direction : 'y',
        overflow : 100,
        padding : 10
    };

    var listView = new PhaserListView.ListView(game, this, bounds, options);

    var newItem = game.add.group(this);
    listView.addMultiple(sprites);
    newItem.nominalHeight = 120;

    listView.add(newItem);

This is actually taken from the example, but the line listView.addMultiple(sprites);

causes issues: updateTransform of children[i] is not a function. When I add the sprites directly to the group "newItem", then I won't get any error, but therefore I see nothing (I mean, the listview nowhere).

So I ask myself, how to actually do it?

mattcolman commented 5 years ago

Hi sorry for the late reply, missed this one. addMultiple expects many arguments for each child, not an array. The example shows ...sprites which splats the array into args. Hope this helps!