Closed jcoppage closed 2 years ago
Yes, you can set the angle of a Zone. Either via setAngle
or by setting its angle
property to a value in degrees.
Here's an example proving it works: https://labs.phaser.io/view.html?src=src\bugs\6133%20zone%20angle.js - click anywhere inside the rotated rectangle.
Arcade Physics bodies cannot be rotated. From the documentation:
/**
* This body's rotation, in degrees, based on its angular acceleration and angular velocity.
* The Body's rotation controls the `angle` of its Game Object.
* It doesn't rotate the Body's own geometry, which is always an axis-aligned rectangle or a circle.
*
* @name Phaser.Physics.Arcade.Body#rotation
* @type {number}
* @since 3.0.0
*/
this.rotation = gameObject.angle;
Rotating the body of a Matter Sprite will, of course, rotate the sprite itself. If you need the body to be at a different angle then you can create it as such on inception using a set of vertices for the body shape.
Also, rotation in Matter is all done in radians, so when changing the angle on a Matter body directly, don't give it a value in degrees.
Running into a similar issue with other phaser game objects; Setting an angle or rotation doesn't do anything. The values remain unchanged - Only directly manipulating their underlying geom
object has an affect.
Running into a similar issue with other phaser game objects; Setting an angle or rotation doesn't do anything. The values remain unchanged - Only directly manipulating their underlying
geom
object has an affect.
Of course, you can rotate Phaser Game Objects, including most shapes. Examples can be seen here: https://labs.phaser.io/index.html?dir=game%20objects/shapes/&q= where you can see arcs, lines, etc all rotating in the examples, just by setting their angle.
If you think you've found a bug, you need to open a separate issue about it and provide example code please.
Trying to rotate a Zone Game Object, setting the angle does not rotate it. Maybe because I'm giving it an Arcade Physics body by adding it to the scene? But that is the only way I can add it to the scene and use it. Also, when using a Matter.js sprite object, when setting the angle to its Body, it ALSO rotates the sprite texture. I just think there should be a feature where I can rotate either the sprite's body, hitArea, or hitZone, etc to fit the shape of the sprite. I feel like this is a very common feature in other game engines. Zone:
this.hitZone = this.scene.add.zone(this.x, this.y).setSize(10, 50);
this.scene.physics.world.enable(this.hitZone);
this.hitZone.setAngle(60) // ZONE IS STILL AT THE SAME ANGLE
this.hitZone.angle = 30 // STILL DOES NOT WORK
Matter.js Spritethis.mapImage = this.scene.matter.add.sprite(this.x,this.y,this.mapImageKey,this.mapImageFrame)
var sprite_body = this.scene.matter.bodies.rectangle(this.x, this.y, 10, 50,{isStatic: true} )
this.scene.matter.body.setAngle(sprite_body, 30)
this.mapImage.setExistingBody(sprite_body)
// THE SPRITE IMAGE GETS ROTATED AS WELL AS THE BODY