Skip to content

Page

Introduction

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

  • 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
    // maxLines: undefined,
    // pageBreak: '\f\n',
});

Set content

  • Set content
    page.setText(content);
    
    • content : String, number, or string array. Can insert pageBreak symbol.
  • Append content
    page.appendText(content);
    
    • content : String, number, or string array. Can insert pageBreak symbol.
  • Clear content
    page.clearText()
    
  • Append page
    page.appendPage(content);   // content in string or array
    
    • content : String, number, or string array. Don't insert pageBreak symbol.

Show page

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

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();
    
  • Get lines of page by index
    var lines = page.getPage(index);
    

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;