Giter VIP home page Giter VIP logo

pixi-multistyle-text's Introduction

pixi-multistyle-text

NPM

Add a MultiStyleText object inside pixi.js to easily create text using different styles.

Example

In the example below, we are defining 4 text styles. default is the default style for the text, and the others matches the tags inside the text.

let text = new MultiStyleText(
  "Let's make some <ml>multiline</ml>\nand <ms>multistyle</ms> text for\n<pixi>Pixi.js!</pixi>",
  {
    default: {
      fontFamily: "Arial",
      fontSize: "24px",
      fill: "#cccccc",
      align: "center",
    },
    ml: {
      fontStyle: "italic",
      fill: "#ff8888",
    },
    ms: {
      fontStyle: "italic",
      fill: "#4488ff",
    },
    pixi: {
      fontSize: "64px",
      fill: "#efefef",
    },
  }
);

Build instructions

$ yarn install
$ yarn build

Usage

text = new MultiStyleText(text, textStyles)

Creates a new MultiStyleText with the given text and styles.

textStyles

Type: { [key: string]: ExtendedTextStyle }

Each key of this dictionary should match with a tag in the text. Use the key default for the default style.

Each ExtendedTextStyle object can have any of the properties of a standard PIXI text style, in addition to a valign property that allows you to specify where text is rendered relative to larger text on the same line ("top", "middle", or "bottom").

The align, wordWrap, wordWrapWidth, and breakWord properties are ignored on all styles except for the default style, which controls those properties for the entire text object.

If text is rendered without any value assigned to a given parameter, Pixi's defaults are used.

Demo

$ yarn demo

License

MIT, see LICENSE.md for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.