Sign in to follow this  
instantia

Reflect body p2

Recommended Posts

But if it still doesn't work, I think you could reset each of its X coordinates.

// Considering its anchor is [0.5,0.5]for(var i=0; i<this.body.shapes[0].vertices.length;i++){    this.body.shapes[0].vertices[i][0] = -this.body.shapes[0].vertices[i][0];}

If it doesn't not work (it probably wouldn't since you would be changing the geometry of an existing shape), you could create your own "vertices" tab like so:

var myVertices = [];for(var i=0; i<this.body.shapes[0].vertices.length;i++){    myVertices.push([-this.body.shapes[0].vertices[i][0], this.body.shapes[0].vertices[i][1]]);}// Now I have a vertices array, with coordinates (which looks like [[-200,200],[-150,100],[50, 150],...])// I erase the current bodythis.clearShapes();// I set the new body with my new coordinatesthis.loadPolygon(myVertices);

Share this post


Link to post
Share on other sites

Created a new polygon.
When the direction of changing.

this.obj.body.clearShapes();this.obj.body.loadPolygon('physics', name+'_'+this.dir);

Yet polygons same. But here is a bug:

set2.jpg

 

Why shifted polygin?

Share this post


Link to post
Share on other sites

{

"salmon_right": [

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 29, 84 , 28, 69 , 73, 65 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 190, 95 , 122, 111 , 91, 104 , 101, 32 , 115, 23 , 155, 26 , 196, 53 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 73, 65 , 101, 32 , 91, 104 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 233, 52 , 237, 65 , 212, 91 , 190, 95 , 196, 53 ]

}

],

"salmon_left": [

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 29, 84 , 28, 69 , 73, 65 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 190, 95 , 122, 111 , 91, 104 , 101, 32 , 115, 23 , 155, 26 , 196, 53 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 73, 65 , 101, 32 , 91, 104 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 233, 52 , 237, 65 , 212, 91 , 190, 95 , 196, 53 ]

}

]

}

Share this post


Link to post
Share on other sites

The interesting thing is that if you put the shift on the same "right", everything works fine.
 

if (this.obj.angle !== this.angleOld) {			if (Math.abs(this.obj.angle) > 90) {					this.obj.scale.setTo(this.scale, -this.scale);				this.dir = 'left';			}			else if (Math.abs(this.obj.angle) <= 90) {					this.obj.scale.setTo(this.scale, this.scale);				this.dir = 'right';			}			if (this.dir !== this.dirOld) {					/*console.log(this.obj.height);*/				this.obj.body.clearShapes();				this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);			}			this.dirOld = this.dir;		}

- not working.


 

if (this.obj.angle !== this.angleOld) {			if (Math.abs(this.obj.angle) > 90) {					this.obj.scale.setTo(this.scale, -this.scale);				this.dir = 'right';			}			else if (Math.abs(this.obj.angle) <= 90) {					this.obj.scale.setTo(this.scale, this.scale);				this.dir = 'right';			}			if (this.dir !== this.dirOld) {					/*console.log(this.obj.height);*/				this.obj.body.clearShapes();				this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);			}			this.dirOld = this.dir;		}

- working.


How so? left = right.

Share this post


Link to post
Share on other sites

solved the problem so:

 

if (Math.abs(this.obj.angle) > 90) this.dir = 'left';else if (Math.abs(this.obj.angle) <= 90) this.dir = 'right';if (this.dir !== this.dirOld) {		this.obj.scale.setTo(this.scale, this.scale);	this.obj.body.clearShapes();	this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);}if (Math.abs(this.obj.angle) > 90) this.obj.scale.setTo(this.scale, -this.scale);else if (Math.abs(this.obj.angle) <= 90) this.obj.scale.setTo(this.scale, this.scale);this.dirOld = this.dir;

a bit expensive(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.