davidfig / pixi-scrollbox

a scrollbox built for pixi.js using a masked box that scrolls vertically and/or horizontally with optional scrollbars
https://www.npmjs.com/package/pixi-scrollbox
MIT License
171 stars 33 forks source link

Is "auto scroll" possible ? #32

Open RegniesAnthony opened 3 years ago

RegniesAnthony commented 3 years ago

Hi, I would like to use it for a chat, so i need to automaticly scroll to the bottom of my scroll box each time i create a scroll box (to watch the most recent messages) is it possible currently ? i didn't find how.

Is there a value that i am supposed to change ?

=================

const scrollBox = new Scrollbox.Scrollbox ({ boxWidth: HUDChatWidth, 
                                                boxHeight: HUDChatHeight,
                                                contentWidth: HUDChatWidth*0.9,
                                                contentHeight: HUDChatHeight*0.9,
                                                dragScroll: true,
                                                scrollbarOffsetHorizontal : 0,
                                                underflow: "none"})

        chat.forEach(m => {
            text += m +"\n";
        })
        scrollBox.content.addChild(new PIXI.Text(text, {fontFamily : 'Arial', 
                                                        fontSize: 24, 
                                                        fill:0xCCCCCC, 
                                                        align : 'left', 
                                                        wordWrap:true, 
                                                        wordWrapWidth: HUDChatWidth -24, 
                                                        height: HUDChatHeight-10, 
                                                        breakWords:true}));
        //here, scroll to the bottom of my scrollBox ?
        scrollBox.update();
davidfig commented 3 years ago

You need to set the bottom of the viewport: scrollbox.content.bottom = scrollbox.content.height should do the trick.