Jump to content

Can I load more than one physics JSON file in preload?


neoRiley
 Share

Recommended Posts

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'); // fails

But I'm getting this error:

 

Phaser.Cache.getPhysicsData: Invalid key/object: "carPhysics / car" libs.js:13
  1. Uncaught TypeError: Cannot read property 'length' of null libs.js:21
  1. Uncaught 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

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

 Share

  • Recently Browsing   0 members

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