Jump to content

Polygon .json scaling


Ocelot
 Share

Recommended Posts

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: 

 

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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