npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixi-game

v0.1.11

Published

> A library makes Pixi.js using easily.

Downloads

8

Readme

Pixi-game

A library makes Pixi.js using easily.

Demo

Online demo

Install

npm install pixi-game
# or
yarn add pixi-game

Class

Game

Extend from PIXI.Application.

new Game(option)

option: As same as option of PIXI.Application.

Members
  • state [Object]
    • __states [Object] The container of all add state container.
    • active [Object]
      • name [String]
      • state [Object] Current running state, extends PIXI.Container.
      • update [Function] Current running function in PIXI.ticker.
    • add [Function]
      • @param name [String] State name.
      • @param state [Object] State extends PIXI.Container.
    • start [Function] Switch render a new state to stage.
      • @param name [String] State of state container.
Example
import * as states from 'components/game'
class App extends Game {
    constructor() {
        super(400, 300, {
            backgroundColor: 0xeeeeee
        })

        Object.keys(states).forEach(state => this.state.add(state, states[state]))

        this.state.start('Boot')

        window.onresize = () =>{
            this.renderer.resize(800, 600)
            this.state.active.state.removeChildren()
            this.state.active.state.rerender()
        }
    }
}

window.game = new App()
document.body.appendChild(window.game.view)

State

Extend from PIXI.Container

new State()

Members
  • game [Object] The instance of Game
  • stage [Object] Equal renderer which is the property of Game's instance.
  • state [Object] As same as Game's state.
  • loader [Object] PIXI.loader.
  • assets [Object] All resource loaded use this.loader.add().
  • add [Function]
    • @param name [String | Object] The loaded resource name or sprite.
  • init [Function] Some init action.
  • preload [Function] Use this.add function to preload resource.
  • create [Function] After all resource loaded, create display Object.
  • update [Function] After displayObjec created, update status.
  • rerener [Function] Rerender all displayObject in stage.
Example
import { State } from 'pixi-game'
import { Text } from 'pixi.js'
import logo from 'assets/logo.png'

let sY = angle = 0
export default class extends State {
    init() {
        this.stage.backgroundColor = 0xeeeeee

        const loading = new Text(
            'loading...',
            {
                fontSize: 50,
                fill: 0xff0f0f
            }
        )
        loading.position.set(this.stage.width / 2, this.stage.height / 2)
        loading.anchor.set(0.5)
        this.loading = loading
        this.add(loading)
    }
    preload() {
        this.loader.add('logo', logo)
        this.loader.onProgress.add(loader => {
            this.loading.text = `loading ${parseInt(loader.progress)}%`
            this.state.start('Home')
        })
    }
    create() {
        this.logo = this.add('logo')
        thi.logo.position.set(this.stage.width / 2, this.stage.height / 4)
        this.logo.anhor.set(0.5)
        sY = this.logo.y
    }
    update() {
        if(angle > Math.PI * 2) angle = 0
        this.logo.y = sY + Math.sin(angle)
        angle += 0.1
    }
}

AnimatedSprite

new AnimatedSprite(baseTexture, spriteSheetJson)

  • @param baseTexture [Object] The instance of PIXI.BaseTexture.
  • @param spriteSheetJson [Object] JSON hash, export from TexturePacker.
  • @return animatedSprite [Object] An animated Sprite.
Example
import redpackJson from 'assets/redpack.json'
const redpack = new AnimatedSprite(this.assets.redpack.texture.baseTexture, redpackJson)
redpack.position.set(571, 255)
redpackX = redpack.x
redpack.animationSpeed = 0.05
redpack.play()
this.redpack = this.add(redpack, gift)

Sample Example

import {
    Game,
    State
} from 'lib'

import logo from 'assets/logo.png'

class Boot extends State {
    init() {
        console.log('Boot init')
    }
    preload() {
        console.log('Boot preload')
        this.loader.add('logo', logo)
    }
    create() {
        console.log('Boot create')

        let basicText = new PIXI.Text('Boot text in pixi')
        this.add(basicText)
        this.add('logo')

        setTimeout(() => {
            this.state.start('Loading')
        }, 3000)
    }
    update() {
        console.log('Boot update')

    }
}

class Loading extends State {
    init() {
        console.log('Loading init')
        this.stage.backgroundColor = 0xff0000
        this.stage.resize(400, 300)
    }
    preload() {
        console.log('Loading preload')
    }
    create() {
        console.log('Loading create')
        let basicText = new PIXI.Text('Loading text in pixi')
        this.add(basicText)
    }
    update() {
        console.log('Loading update')
    }
}

const states = {
    Boot,
    Loading
}

class App extends Game {
    constructor() {
        super(400, 300, {
            backgroundColor: 0xeeeeee
        })

        Object.keys(states).forEach(state => this.state.add(state, states[state]))

        this.state.start('Boot')
    }
}

const app = new App()
document.body.appendChild(app.view)

License

MIT