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
v3.11 warning : Local data URIs are not supported: #3897
Comments
Don't use base64 assets? It's a really bad idea for games and brings absolutely zero benefits to the table. Games are not websites. Don't package them or treat them in the same way.
Solution: There will be no support for base64 assets loaded via the Loader, for the reason stated above, however you can add them directly into the Texture Manager:
You'll have to wait for every single texture added in this way to dispatch an 'addtexture' event before you can use it with a Game Object. In short, don't use base64. |
#3966 . @photonstorm var config = { }; var imageData = 'data:image/png;base64, anyBASE64IMAGEKEY'; /** Create Function **/
} function update() { } |
@photonstorm sorry for the throwback, but could you please elaborate on why it's a bad idea for small images? I stumbled upon this issue because I was embedding a game in a react app (and the react default script uses webpack, which is automatically configured to url encode small images) |
It's not really a very sensible optimization for websites either. The moment you base64 a file, several things happen:
I'm aware this is a common practice for web sites, but games aren't web sites and shouldn't be treated in the same way. |
Thanks for the details! |
I've been spending hours trying to work around this bug to use phaser as a library in another webpack project. It's ironic that an HTML game framework can't work with the most common HTML tooling - webpack. Here are some workarounds |
I ran into an issue including phaser 3 into my react app. By default, the webpack config was loading in small images differently that were not compatible with phaser. To solve this in a react app, you can override the webpack config environment variable react uses by setting the variable as shown below in your react .env file. By default, the react webpack config has it at 10,000. IMAGE_INLINE_SIZE_LIMIT=1 |
@photonstorm |
Yes, that is what I am using but it was more involved- had to create a promise and a listener and await the promise to make sure the textures are loaded. |
Here is an asynchronous function to load base64 image data in Phaser. I am using it successfully alongside the
import { Scene, Textures } from "phaser";
const loadBase64Image = (props: {
data: any;
key: string;
scene: Scene;
}) => {
return new Promise<void>((resolve) => {
props.scene.textures.once(Textures.Events.ADD, () => {
resolve();
});
props.scene.textures.addBase64(props.key, props.data);
});
}; You can use it like so: import tileset from "./tileset.png";
new Game({
scene: {
create: async function (this: Scene) {
await loadBase64Image({
data: tileset,
key: "tileset",
scene: this,
});
this.add.image("tileset");
},
},
}); This example assumes that you have a file called |
If you are using react, adding the function below to handle image loading addressed this issue for me.
|
I use webpack & url-loader to handle png, like this:
the img variable is a base64 string, but it renders nothing and in console has a warning
Local data URIs are not supported: cokecan
,phaser version is 3.11.0, what should I do?The text was updated successfully, but these errors were encountered: