1

I am currently recoding a game and im having problems with the rendering engine. i think that the problem is in my file paths, because the old (and identically coded) version works just fine.

I've tried moving the program to another disk, changing the name, including full file path, including relative file path and ive tried to put the output into the debug console, which only crashes the console. I've also set up a check that makes sure the program doesnt display the tile when its value is null, but that just makes it so that it doesnt do anything.

this is the file path for the textures: D:\programs\HTML5_JavaScript\mipmap\assets\textures\tileSetSand

this is my current code for the texture importer:

tileSetSand=[];
players=[];

function setup(){

    for(i=0;i<115;i++){

        print(i);
        tileSetSand[i]=loadImage('D:/programs/HTML5_JavaScript/mipmap/assets/textures/tileSetSand/tile ('+i+').PNG');

    }

    for(i=0;i<2;i++){

        players[i]=loadImage('D:/programs/HTML5_JavaScript/mipmap/assets/textures/player ('+i+').PNG');

    }
}

this is the old, functioning code

function setup() {

  tileSetSand=[];

  for(i=0;i<117;i++){

    tileSetSand[i]=loadImage('D:/maart/Documents/Processing/mipmap_local/assets/sprite ('+i+').PNG');

  }

  //loading all the images and sprites into an array

  createCanvas(1000,1000);

}

this is where i utilize the images (this.texture is 3)

display : function(){

    if(tileSetSand[this.texture]!=null){

        image(tileSetSand[this.texture],this.xPos,this.yPos,20,20);

    }

  },

the expected output is this function drawing the image specified by this.texture into the canvas at xPos,yPos. However, it does not. i have no clue why.

  • `Unable to get property 'x' of undefined or null reference` this means that somewhere you have an object and you try to access `x` property of it, bu the object is null or undefined. Is there other part of your code where you try to access `x` ? – Vencovsky Mar 26 '19 at 10:57
  • I think the loadImage() function causes this problem as its trying to access the properties of the image inside the file path but its returning null (also, it gives this error about twice a second) – Maarten Mosk Mar 26 '19 at 11:03
  • try changing `/` to ``\\`` – Vencovsky Mar 26 '19 at 11:04
  • it seems that it just finds nothing at the specified file path, because the exact same code works perfectly for the old version. (you mean in the file path right?) – Maarten Mosk Mar 26 '19 at 11:22
  • Are you trying this on a server or local server? loadImage doesn't work in a local environment. This is a bit different from Processing (where your old project was build with?). More info can be found here https://p5js.org/examples/image-load-and-display-image.html – Peter Bode Mar 26 '19 at 13:35
  • Can you please post a [mcve]? Can you narrow this down to a single image that's not loading correctly? – Kevin Workman Mar 26 '19 at 16:38
  • It seems that p5.js just REALLY doesnt like it when i use setup() two times… it works now &thanks for the help! – Maarten Mosk Mar 28 '19 at 13:15
  • @MaartenMosk as a side note look into running a local webserver (can be wamp/python http module, node.js http-server, etc.) and using paths relative to the server instead of hardcoded locations on the hard drive. this will make it easier when you choose to upload your work online. Good luck – George Profenza Mar 28 '19 at 15:31

1 Answers1

0

It appears that i was using another setup() function elsewhere in the project, and that caused the setup() here to not work. I found this out when i placed my variable callers into my setup(), which caused those variables to become null, as they werent being called properly.