neoRiley Posted April 19, 2014 Share Posted April 19, 2014 This is what I'm trying to do: // preloaderload.image('car', 'images/raceCar.png', 28, 50);load.physics('carPhysics', 'images/raceCarPhysics.json');load.image('level', 'images/maps/level.png', 1664, 2048);load.physics('physicsData', 'maps/levelPhysics.json');// createmap = game.add.sprite(1664*0.5, 1024, 'level');game.physics.p2.enableBody(map, true);map.body.kinematic = true;map.body.clearShapes();map.body.loadPolygon('physicsData', 'level');app.player = player = game.add.sprite(150, 320, 'car');player.anchor.setTo(0.5, 0.5);player.collideWorldBounds = true;game.physics.p2.enableBody(player, true);player.body.clearShapes();player.body.loadPolygon('carPhysics', 'car'); // failsBut I'm getting this error: Phaser.Cache.getPhysicsData: Invalid key/object: "carPhysics / car" libs.js:13Uncaught TypeError: Cannot read property 'length' of null libs.js:21Uncaught TypeError: Cannot read property 'left' of null If I load physicsData only, it works. But if I load the car physics I keep getting this error. I've quadruple checked spelling/case/file locations - it's all correct. Is there something simple I'm missing with trying to load multiple physics files? Link to comment Share on other sites More sharing options...
neoRiley Posted April 19, 2014 Author Share Posted April 19, 2014 SOLVED: I was an idiot and the name of the instance in the carPhysics wasn't 'car', it was 'raceCar'. When you import your image into PhysicsEditor, the instance name is the name of the image that's imported. I thought it was the sprite reference name I had to use. I also found that I could have simply added another image to the same physics file so that all my sprite polys were in the same JSON file instead of multiple. Sorry for the wasted post. Link to comment Share on other sites More sharing options...
rich Posted April 20, 2014 Share Posted April 20, 2014 Glad you solved it and yeah I would try and put all your physics data into a single file if you can, but if it starts getting too heavy splitting it up doesn't matter - definitely don't use 1 file per object though! Link to comment Share on other sites More sharing options...
Recommended Posts