Coder Social home page Coder Social logo

pixi-ex's Introduction

Pixi extended - Useful utilities for PixiJS


Features

  • Enhanced built-in functions
  • Convenience functions for creating sprites, texts etc.
  • Written in TypeScript
  • Zero dependencies

API

  • resize - Resize the canvas and retain the correct proportions

  • getGlobalPosition - Get the global position of a display object

  • getOverlappingArea - Get overlapping area of two display objects

  • drawHitArea - Debug your display objects hit areas

  • onClick - Sets interactive to true, changes mouse cursor to pointer and adds a click listener to the display object.

  • handleResize - Make text objects look good even when resized

  • getAllChildren - Get all children (including the input display object) from this point in the hierarchy.

  • centerX - Center a display object on the horizontal axis.

  • centerY - Center a display object on the vertical axis.

  • useAutoFullScreen - Automatically resize canvas to be full screen.

  • getGameScale - Get the game scale after resize

Constructors

Benefits:

  • Always adds the object to a parent
  • No need to use the new keyword ("new Sprite" -> "sprite")
  • AnimatedSprite auto-plays
  • Enforces a TextStyle to be set on Text
sprite(parent: Container, texture?: Texture): Sprite
animatedSprite(parent: Container, textures?: Texture[]): AnimatedSprite
text(parent: Container, textStyle: Partial<ITextStyle>, textContent?: string): Text
container(parent: Container): Container
graphics(parent: Container): Graphics
rectangle(rectangle: {
  x: number
  y: number
  width: number
  height: number
}): Rectangle

Enhanced built-ins

beginFill(graphics: Graphics, color: number): Graphics

Also calls clear

setPosition(
  displayObject: Container,
  position: { x: number; y: number },
): void

Accepts a position object

drawRect(
  graphics: Graphics,
  rectangle: Rectangle | { x: number; y: number; width: number; height: number },
): Graphics

Accepts a Rectangle

Helpers

  • getWidth

  • getHeight

  • centerX

  • centerY

  • getAllChildren

  • centerPivot


๐Ÿ“ฆ Install

npm install pixi-ex

Example usage

Check out app/index.js for example usages

pixi-ex's People

Contributors

dependabot[bot] avatar sajmoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pixi-ex's Issues

Unit tests are broken

Reason: Importing pixi in src/index.ts to get type definitions breaks tests since it's not possible to import pixi in node (needs access to window object).

Possible solutions:

  • Is it possible to import the pixi types separately from the rest of the project?
  • Polyfill window?

Fix tests

Need to be able to run pixi in node

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.