Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
/expo-pixiPublic archive

Tools for using pixi.js in Expo

License

NotificationsYou must be signed in to change notification settings

expo/expo-pixi

Repository files navigation

Tools to usePixi.js in Expo!

To get started:yarn add expo-pixi in your Expo project and import it withimport ExpoPixi from 'expo-pixi';.

Side-Effects

To use Pixi.js with Expo & React Native you will want to import a modified version of Pixi.js like so:

// ✅import{PIXI}from'expo-pixi';// ❌import*asPIXIfrom'pixi.js';

Now you can create a new Application the way you would on the web, but be sure to pass in aWebGLRenderingContext.

// ✅constapp=newPIXI.Application({ context});// ❌constapp=ExpoPIXI.application({ context});

Finally, because of the way React Native currently works you must load in assets asynchronously.

/* * Accepts: * - Expo.Asset: import { Asset } from 'expo-asset'; Asset.fromModule( ... ); * - URL (with file extension): 'http://i.imgur.com/uwrbErh.png' * - Static Resource: require('./icon.png') */// ✅constsprite=awaitPIXI.Sprite.fromExpoAsync('http://i.imgur.com/uwrbErh.png');// ORconsttexture=awaitPIXI.Texture.fromExpoAsync('http://i.imgur.com/uwrbErh.png');// ❌constsprite=awaitExpoPIXI.spriteAsync('http://i.imgur.com/uwrbErh.png');// ORconsttexture=awaitExpoPIXI.textureAsync('http://i.imgur.com/uwrbErh.png');

Using web syntax will return aPromise, and throw a warning. It's bad practice, but if the asset is loaded already, this will work without throwing a warning.

constsprite=awaitPIXI.Sprite.from(require('./icon.png'));// > console.warning(PIXI.Sprite.from(asset: ${typeof asset}) is not supported. Returning a Promise!);// ORconsttexture=awaitPIXI.Texture.from(require('./icon.png'));// > console.warning(PIXI.Texture.from(asset: ${typeof asset}) is not supported. Returning a Promise!);

Functions

ExpoPixi.application(props): PIXI.Application

Deprecated: Usenew PIXI.Application({ context });

A helper function to create aPIXI.Application from a WebGL context.EXGL knows to end a frame when the function:endFrameEXP is called on the GL context.

context is the only required prop.

Learn more about PIXI.Application props

ExpoPixi.textureAsync(resource: any): Promise

Deprecated: UsePIXI.Texture.fromExpoAsync(resource);

ExpoPixi.spriteAsync(resource: any): Promise

Deprecated: UsePIXI.Sprite.fromExpoAsync(resource);

a helper function to resolve the asset passed in.textureAsync accepts:

You cannot send in relative string paths as Metro Bundler looks for static resources.


ExpoPixi.sprite({ localUri: string, width: number, height: number }): PIXI.Sprite

Deprecated: UsePIXI.Sprite.from(resource);

ExpoPixi.texture({ localUri: string, width: number, height: number }): PIXI.Texture

Deprecated: UsePIXI.Texture.from(resource);

Pixi.js does a type check so we wrap our asset in aHTMLImageElement shim.

ExpoPixi.Sketch

A component used for drawing smooth signatures and sketches.

See the sketch example on how to save the images!

Notice: the edges and ends are not rounded as this is not supported in PIXI yet:Issue

Props

PropertyTypeDefaultDescription
strokeColornumber0x000000Color of the lines
strokeWidthnumber10Weight of the lines
strokeAlphanumber1Opacity of the lines
onChange() => PIXI.RenderernullInvoked whenever a user is done drawing a line
onReady() => WebGLRenderingContextnullInvoked when the GL context is ready to be used

ExpoPixi.FilterImage

A Image component that uses PIXI.Filter

Props

PropertyTypeDefaultDescription
resizeModestringnullCurrently only supportscover, andcontain
filtersArray<PIXI.Filter>nullArray of filters to apply to the image
sourcenumber, string, Expo.AssetnullSource can be a static resource, image url (not{uri}), or anExpo.Asset

Example

Snack

importReactfrom'react';importExpofrom'expo';import{PIXI}from'expo-pixi';exportdefault()=>(<Expo.GLViewstyle={{flex:1}}onContextCreate={asynccontext=>{constapp=newPIXI.Application({ context});constsprite=awaitPIXI.Sprite.fromExpoAsync('http://i.imgur.com/uwrbErh.png',);app.stage.addChild(sprite);}}/>);

NPM

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp