I've recently started working with JS programming and pixi JS. I'm attempting to load a texture atlas from a json file following this tutorial module: https://github.com/kittykatattack/learningPixi#spriteproperties
For my setup, I am using typescript, node js, and parcel bundler to keep things simple. However, I am facing an issue where my texture atlas is not loading even though I am using PIXI.loader. Strangely, when I tried a similar example directly in an HTML file, it worked without any problems.
The versions of the tools I am using are: PIXI 5.3.3 (latest release), parcel 1.12.4, Typescript 4.0.3
This is my index.ts:
import textPack from "./assets/textPack.json"
...
let loader = PIXI.loader.shared
loader.add("./assets/textPack.json")
.load(setup)
function setup {
let id = loader.resources["./assets/textPack.json"].textures
let soldier = new PIXI.Sprite(id["soldier.png"])
app.stage.addChild(soldier)
}
Here is my package.json configuration:
{
"name": "parcel-tuto",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"parcel-bundler": "^1.12.4",
"parcel-plugin-asset-copier": "^1.1.0",
"pixi-sound": "^3.0.5",
"pixi.js": "^5.3.3",
"typescript": "^4.0.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/.bin/parcel index.html"
},
"assetsPath": "src/assets/",
"keywords": ["assets"],
"author": "",
"license": "ISC"
}
When I run Typescript, I get the error message TS2532: Object is possibly 'undefined'. Moreover, the .json and .png files associated with the atlas are not being copied into the parcel dist folder.
A console.log on loader.resources['...'] shows the JSON data parsing error as follows:
json datas :
Resource {_flags: 2, name: "./assets/textPack.json", url: "./assets/textPack.json", extension: "json", data: null, …}
children: Array(0)
length: 0
__proto__: Array(0)
crossOrigin: ""
data: null
error: Error: Error trying to parse loaded json: SyntaxError: Unexpected token < in JSON at position 0 at Resource.abort (http://localhost:1234/src.f10117fe.js:28599:18) at Resource._xhrOnLoad (http://localhost:1234/src.f10117fe.js:29046:18)
extension: "json"
loadType: 1
metadata: {}
name: "./assets/textPack.json"
...
In summary, nothing seems to be working as expected. Has anyone encountered a similar issue before?
Thank you for your assistance.