Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a convenience Texture API to handle invalid URLs more effectively #6687

Merged
merged 4 commits into from
Jun 14, 2020

Conversation

bigtimebuddy
Copy link
Member

@bigtimebuddy bigtimebuddy commented Jun 9, 2020

This creates a convenience method for loading remote URLs. Fixes #6514. There are currently ways to error handle loads, and they suck and are confusing/verbose to use. This adds an alternative path for loading Texture by returning a Promise.

Option 1, manually load resource 👎

const texture = PIXI.Texture.from('http://path/to/wherever.png', {
  resourceOptions: { autoLoad: false }}
);
await texture.baseTexture.resource.load();

Option 2, subscribe to onError 👎

const texture = PIXI.Texture.from('http://path/to/wherever.png', {
  resourceOptions: { autoLoad: false }}
);
texture.baseTexture.resource.onError.add(() => {
  // handle error here
});

Options 3, This PR 👍

const texture = await PIXI.Texture.fromURL('http://path/to/wherever.png');

@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2020

Codecov Report

Merging #6687 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               dev     #6687   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines          671       671           
=========================================
  Hits           671       671           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f1a88d...b9ec089. Read the comment docs.

@bigtimebuddy bigtimebuddy added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Jun 14, 2020
@bigtimebuddy bigtimebuddy merged commit 438819e into dev Jun 14, 2020
@bigtimebuddy bigtimebuddy deleted the dev-texture-from-url branch June 14, 2020 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Texture.from succeeds in generating a valid texture from an invalid relative URL
4 participants