# rotation and angles

## Recommended Posts

Hello,

I am very very new to phaser and just started playing around with it.

I am trying to find a way in which i can rotate (using rotation, angle or any other method can be advised) the world of a game in which the center point of rotation is the center of the camera, and not position 0,0 of the world itself.

This means the center point for rotation is dynamic and based on the center point of the current camera.

Is it possible to do with phaser?

I believe I am looking for a way to offset the point of rotation for the world object of the game.

Eli

##### Share on other sites

Just to be sure is this your goal:

http://www.tonypa.pri.ee/tbw/tut21.html

and for the moment I don't have the answer but I'm curious too.

##### Share on other sites

Exactly what i am looking for.

##### Share on other sites

Anyone know if this is possible? change the anchor position of the world for rotation?

Thanks again,

Eli

##### Share on other sites

• 3 months later...

Hi,

I want to do something very similar. Is there any way to archive this?

Best solution would be a rotation-property in the camera object!

##### Share on other sites

I found a way to rotate the camera around a given point:

`game.camera.displayObject.pivot.x = game.camera.view.x + game.camera.view.width/2;game.camera.displayObject.pivot.y = game.camera.view.y + game.camera.view.height/2;game.camera.displayObject.rotation = Math.PI/4; // place your rotation here `

I sill have some trouble now: When i place my camera to the player its not working anymore:

`game.camera.focusOnXY(player.x, player.y);`

I think the pivot-Point has some effect on that positioning ... but Iam not sure how to calculate the right position.

##### Share on other sites

• 1 month later...

I'd also like to know if anyone has had any luck with this.  I've been able to rotate the tilemap around my player character, but the collisions stay where they were when the map was initially created.

##### Share on other sites

• 3 weeks later...

I've tried rotating the camera and it works if I set the bounds of world to negative startvalues. This is in order to offset the origin of camera, etc. Without this the camera keeps rotating at [0,0] (top left) of canvas.

There are a few things that makes this a bad choice. First of all the "fixedToCamera" does not work, since the camera is in fact rotating. In essence all "fixedToCamera"-objects become part of the world. Also, setting camera.displayObject.pivot breaks the "follow" setting of the camera.

These are my findings, perhaps it's not broken, I'm just not using it correctly.

I hope there is another way, like... rotating world, game, stage or something like that.

##### Share on other sites

I hope there is another way, like... rotating world, game, stage or something like that.

I went through all of the examples on the Phaser example page and I found EXACTLY what I was looking for.

http://examples.phaser.io/_site/view_full.html?d=input&f=cursor+key+movement.js&t=cursor%20key%20movement

In the example the world is rotating, not the camera.

I sure hope I will be able to setup all my configurations without limitations this way. For instance specifying some kind of origin of the rotation. According to what I read earlier about rotation on the World class, it always rotates out of [0,0] which is not what I want, perhaps there is a way to modify this anyway.

Gonna try this out tomorrow or day after tomorrow. Let's hope for the best!

##### Share on other sites

Gonna try this out tomorrow or day after tomorrow. Let's hope for the best!

Initial findings are not great.

The world does rotate, yay! but...

It's a bit of a hassle to reset bounds every time the player moves to set the origin at the center of the screen/camera where the player is.

Also, the bounds are quite useful and I'm not sure that the game would be optimal if the bounds keep changing.

Objects that have the property "fixedToCamera" set to true, does not appear to work as intended, they rotate with the world.

I'll have to keep at it I guess.

##### Share on other sites

• 3 months later...

Hi,

I want to do something very similar. Is there any way to archive this?

Best solution would be a rotation-property in the camera object!

+1

##### Share on other sites

See my post there, I cannot make that snipped work, instead of rotation it moves left and right. Demo: http://jsfiddle.net/luckylooke/uL37am1h/4/

Ok I didnt notice SHIFT key must be pressed

Edited by luckylooke