Skip to content

amoyjs/query

Repository files navigation

query

A jQuery-like pixi.js selector.

NPM Version NPM Downloads size

Usage

import { Application, Text, Container, Sprite } from 'pixi.js'
import query from '@amoy/query'

const game = new Application({
    width: window.innerWidth,
    height: window.innerHeight,
})

query(game.stage)

const t1 = new Text('Hello World.', {
    fill: 0xffffff,
})
t1.class = 'text'
t1.x = 200
t1.y = 200
const t2 = new Text('Hello World.', {
    fill: 0xffffff,
})
t2.name = 'text'
t2.x = 300
t2.y = 300
const s1 = Sprite.from(document.querySelector('img'))
game.stage.addChild(t1, t2, s1)

$('[class=text]') // t1
// or
$('.text') // t1
$('[name=text]') // t2

Contribution

How to extend a method:

import query from '@amoy/query'

query.extend({
    methodName() {
        for (let i = 0; i < this.length; i++) {
            // this[i]
            // do something on `this[i]`
        }
    }
})

$('sprite').methodName()