Open 7yl4r opened 9 years ago
To fix this is to use a json outline of the sprites as described in this tutorial. So something like:
vm.preload = function(){
// stuff...
// load the physics data json
game.load.physics('asteroidPhysics', 'asteroid_physics.json');
// more stuff..
}
// even more stuff...
vm.asteroid = vm.game.add.sprite(
rnd(w*2/3.0, w*9/10.0),
rnd(h/10.0, h*9/10.0),
'a3');
// remove all of the current collision shapes from the physics body
vm.asteroid.body.clearShapes();
// load our polygon physics data
vm.asteroid.body.loadPolygon('asteroidPhysics', 'asteroid1');
first we need to get those .json files for the ship and the asteroids, and the recommended software is windows/mac exclusive (boo).
file format spec:
{ {% for body in bodies %}
{% if not forloop.first %}, {% endif %}
"{{body.name}}": [
{% for fixture in body.fixtures %}{% if not forloop.first %} ,{% endif %}{% for polygon in fixture.polygons %}{% if not forloop.first %} ,{% endif %}
{
"density": {{fixture.density}}, "friction": {{fixture.friction}}, "bounce": {{fixture.bounce}}, {% if fixture.isSensor %}"isSensor"=true, {% endif %}
"filter": { "categoryBits": {{fixture.filter_categoryBits}}, "maskBits": {{fixture.filter_maskBits}} },
"shape": [ {% for point in polygon %} {% if not forloop.first %}, {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]
} {% endfor %} {% endfor %}
]
{% endfor %}
}
(from here)