Page

Introduction

Display text page by page on text object, bbcode text object, or tag text boject.

  • Author: Rex
  • Behavior of text object

Live demos

Usage

Sample code

Install plugin

Load minify file

  • Load plugin (minify file) in preload stage
    scene.load.plugin('rextextpageplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rextextpageplugin.min.js', true);
    
  • Add page behavior
    var page = scene.plugins.get('rextextpageplugin').add(textGameObject, config);
    

Import plugin

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Install plugin in configuration of game
    import TextPagePlugin from 'phaser3-rex-plugins/plugins/textpage-plugin.js';
    var config = {
        // ...
        plugins: {
            global: [{
                key: 'rexTextPage',
                plugin: TextPagePlugin,
                start: true
            },
            // ...
            ]
        }
        // ...
    };
    var game = new Phaser.Game(config);
    
  • Add page behavior
    var page = scene.plugins.get('rexTextPage').add(textGameObject, config);
    

Import class

  • Install rex plugins from npm
    npm i phaser3-rex-plugins
    
  • Import class
    import TextPage from 'phaser3-rex-plugins/plugins/textpage.js';
    
  • Add page behavior
    var page = new TextPage(textGameObject, config);
    

Create instance

var page = scene.plugins.get('rexTextPage').add(textGameObject, {
    //text: '',       // content in string or array
});

Set content

  • Set text
    page.setText(text);   // content in string or array
    
  • Append text
    page.appendText(text); // content in string or array
    

Show page

  • Display current page
    page.showPage();
    
  • Display next page
    page.showNextPage();
    
  • Display previous page
    page.showPreviousPage();
    

Note

Initial page index is -1, so user could call page.showNextPage() to display first page.

Get lines of page

  • Get lines of current page
    var lines = page.getPage();
    
  • Get lines of next page
    var lines = page.getNextPage();
    
  • Get lines of previous page
    var lines = page.getPreviousPage();
    

Other properties

  • Is last page
    var isLastPage = page.isLastPage;
    
  • Is first page
    var isLastPage = page.isFirstPage;
    
  • Current page index
    var pageIndex = page.pageIndex;
    
  • Number of pages
    var pageIndex = page.pageCount;