Jump to content

V3 loader - localhost and crossOrigin


Recommended Posts

I am new to v3 and running into a couple of issues...


Firstly. I am making a game with my Girlfriend to teach her some JavaScript. 

She is afraid of using commands or installing a webserver on her mac, so I am trying to make crossOrigin work to load textures.


I am using an array of objects that store the name and url, I then add the crossOrigin msg "behind the scenes":

var textures = [  { name: "burger", url: "images/Hamburger.png" },  { name: "moon", url: "images/Lunaone_1.png" }];
var l = textures.length;for ( var i = 0; i < l; i += 1 ) {  textures[i].crossOrigin = "Anonymous";  loader.add( textures[i] );}

However when I try to use the textures:

var burger = new PIXI.Sprite( textures["burger"].texture );

I get the following error:

Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at file:///C:/Users/Oliver/Documents/pirate-game/images/Hamburger.png may not be loaded.

Is there something I can do here without having to install a webserver?

Link to comment
Share on other sites

Without telling chrome to allow file:// protocol access from local (with a command line param) this will fail because it is a security violation. Also, if your opening a file:// locally, and loading a file:// then that isn't cross origin IIRC.


Running a local server is easier than using a special launch of chrome most of the time. You can just install the `http-server` module (npm i -g http-server), then start it with 4 characters:

hs .

Doesn't get much easier than that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...