Ocelot Posted April 9, 2016 Share Posted April 9, 2016 Hi, I want to scale both sprite and .json physics file, is that possible and if so, how? I ve seen a few posts about that but no answers. Thank you Link to comment Share on other sites More sharing options...
megmut Posted April 10, 2016 Share Posted April 10, 2016 Sorry, can you be more specific? You can scale any pixi drawn object in Phaser by using: spriteA.scale.setTo(0.5); // sets x and y to 0.5 spriteB.scale.setTo(0.4, 0.6) // setting x and y individually, will cause stretching Update: I just did some reading and it's not possible to use scaling on a polygon when the physics is applied, or at least not with the phaser engine. Someone has written a nice chunk of code to do this: function resizePolygon(originalPhysicsKey, newPhysicsKey, shapeKey, scale){ var newData = []; var data = this.game.cache.getPhysicsData(originalPhysicsKey, shapeKey); for (var i = 0; i < data.length; i++) { var vertices = []; for (var j = 0; j < data[i].shape.length; j += 2) { vertices[j] = data[i].shape[j] * scale; vertices[j+1] = data[i].shape[j+1] * scale; }newData.push({shape : vertices}); }var item = {}; item[shapeKey] = newData;game.load.physics(newPhysicsKey, '', item); // //debugPolygon(newPhysicsKey, shapeKey); } Read more about it here: WombatTurkey 1 Link to comment Share on other sites More sharing options...
Ocelot Posted April 10, 2016 Author Share Posted April 10, 2016 Thank you , I will try using that code u posted. EDIT: Just one question about that, I will try it anyway, but can that scale a .json file polygon created in physics editor, or only "manually" created polygons? Link to comment Share on other sites More sharing options...
Recommended Posts