How to load XML files both offline and online for use in a 2D JavaScript Array?



I have been working on a little project in my free time sporadically since June. It is an open source clone of SimTower with original, higher resolution graphics I have made.


At first, I made a webpage that loaded a bunch of images into a 2D array to make a pretty picture that one could scroll through. The main problem then was that certain images (the ones for lobbies) that were supposed to repeat until they reached the edge did not work correctly (because the space given for them is not equal to a multiple of their width and in the future the player will need to be able to draw lobbies with 1 tile-width accuracy).


I decided that the code I was using for loading images into an array could not be reused once I add a simulation and animations so I decided to put the information for the rooms and lobbies into separate XML files that should be loaded by JavaScript to gather the information (price and picture being what matters at the moment).


The main problem I have run into is that when trying to load the page with all the data created locally is that all 3 major browsers (Firefox, Chrome, and IE11) throw me error messages about not being able to open files using Http requests.


Once I find out how to load XML files with JavaScript (both online and offline), I will need to figure out how to put the right data in the right place (at the moment, I just want the picture of the rooms to show up in the correct tiles and for their price to be deducted from the budget once placed).


In short this is what I need help with first is this:


Loading XML files using JavaScript regardless of whether the game is online (github) or offline (when I'm making it or when the player downloads it) and making use of the data within the XML files (what images to use at various times and what the stats should be).


No comments:

Post a Comment