-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Bug: Resolver ignores resolution
of asset in v8?
#10108
Comments
heya! thankyou for posting, Im not sure |
if the names were changed from |
it looks like you are using assetpack, so I think you need to add a json resolver so pixi can tell what resolution it is and here is the code snippet import { Resolver, extensions, resolveTextureUrl, ResolveURLParser, ExtensionType } from 'pixi.js';
export const resolveJsonUrl = {
extension: ExtensionType.ResolveParser,
test: (value: string): boolean =>
Resolver.RETINA_PREFIX.test(value) && value.endsWith('.json'),
parse: resolveTextureUrl.parse,
} as ResolveURLParser;
extensions.add(resolveJsonUrl); it is also interesting that this worked in v7 but not v8. I dont believe much was changed between the two versions when it comes to assets |
@Zyie's solution works. I think where I got side-tracked is that back when I was attempting to use assetpack with Pixi.js, after extensive debugging I realized that resolutions were not being considered because assetpack would output names such as It may be worth documenting whether the above approach works with both v7 and v8, or only with v8. |
I've added the json resolver by default now, so hopefully all is fixed |
Current Behavior
Using Pixi v8, I'm unable to load an asset of the desired resolution when creating a sprite using code such as:
Take the following manifest as an example. It is generated by a slightly modified version of
assetpack
which adds the format of the underlying images to a SpriteSheet JSON file's name:Note how the
src
property includes 4 different resolutions. Due to how I'm packaging my assets, @1x is actually 10 times the size of the "natural" size of the assets, therefore 0.1x would actually be a @1x asset, 0.2x would be a @2x asset, and so on.I initialize
Assets
as follows:Note how by setting
texturePreference.resolution
to0.3
I am signaling that I wanttextures/house/house@0.3x.png.json
to be used.This worked fine in Pixi.js v7 but doesn't seem to work in v8.
Stepping through the execution of Pixi's
Resolver
with a debugger, I noticed the following:resolve
method ofResolver.ts
looks for an asset matching the resolution0.3
here.assets
(defined asthis._assetMap[key]
), the asset has the following shape:Notice how the asset object has a
format
property, which is used by thepreferredOrder
logic to check for a match. However, it doesn't have aresolution
property.resolution
is what would be used to identify whether the asset matches the desired resolution.Due the
resolution
property missing, the resolver defaults tothis._resolverHash[key] = assets[0];
(in my case picking the0.1x
resolution asset).Digging deeper, within the
add
there is logic for detecting the "retina" resolution of an asset, but in my specific case it's not being triggered.add
there is a section wherethis._parsers
are used on the asset.{ "extension": "resolve-parser", parse: Function, test: Function }
parse
function is defined inresolveTextureUrl
. Notice how it sets aresolution
field if it detects a resolution in the file name.parse
is run,test
must run successfullytest
, we see that it'sloadTextures.test
checkExtension
. Note how it checks that the extension is within['.jpeg', '.jpg', '.png', '.webp', '.avif']
..json
.Expected Behavior
The correct resolution asset is loaded
Steps to Reproduce
The first defined (lowest) resolution asset is loaded instead.
Environment
pixi.js
version:8.0.0-rc.3
Possible Solution
Consider adding
.json
as a valid image format withinloadTextures.test
or switching to a different method of testing the asset.Additional Information
This worked fine in v7 but must have been broken due to the extensive refactoring of v8
The text was updated successfully, but these errors were encountered: