Polygon .json scaling

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: 


Share this post

Link to post
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?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.