TomLeGrand

Problem with world.scale.set() and angleToPointer()

Recommended Posts

Hi,

I'm currently making a litlle top-down shooter game with Phaser.
I'm using the method bellow to aim towards the mouse's position.

sprite.rotation = game.physics.arcade.angleToPointer(sprite);

This work very well, but I would like to allow the player to zoom in and out. I was following this idea : http://jsfiddle.net/NMNJ7/25/ which use the game.world.scale.set() method;

But when I change the world's scaling, the angleToPointer() method is completly lost and it's impossible to aim.

You can try this little exemple I've made to understand what goes wrong : https://jsfiddle.net/TomLeGrand/uh7d10eu/127/

Do someone has an idea to fix this?

Thanks for you futur help

Share this post


Link to post
Share on other sites

Just played with it and apparently you have to also scale the input. As weird as it is, you don't need the same scale, but the reciprocal of it.

game.input.scale.set(1 / 1.35);

 

P.S. Call this just after setting the world's scale.

P.S.2 This assumes you have "square" scaling, i.e. scale.x === scale.y

 

Share this post


Link to post
Share on other sites
15 hours ago, TomLeGrand said:

Cool it works well :)
 

By that do you mean that my world's scaling need to be equal on height and on width ?

Yes, exactly. Any .set() you do on a Phaser.Point with only one argument, it applies that argument to both x and y. It's unlikely that they'd be different, just thought I'd mention it.

 

By the way, if you don't mind me asking, what's your aim with scaling the whole world? What are you trying to achieve?

Share this post


Link to post
Share on other sites

I want to allow the player to see farthest depending on the weapon the player carrying. If the player use a sniper, he can see further than an other weapon (I hope you understand, english isn't my mother langage)

I've got an other topic 

Other problems I have, have been resolved. You can try the example in this topic to see more about what I'm trying to achieve :)

Share this post


Link to post
Share on other sites

Yup, I got it now. Maybe the more "correct" approach would be to play with the camera, not with the world (as seen from the other topic this introduces other problems), but this is just what I would try.

Share this post


Link to post
Share on other sites

I'm applying the same fix to my little project but it doesn't work.

I am using arcade.moveToPointer, trying different combinations of changing scale of input, world and camera don't work. I also tried 1/scale for input, but it doesn't work.

player.rotation = game.physics.arcade.moveToPointer(player,  256);
game.camera.scale.set(scale)
game.input.scale.set(1/scale)

 

The position the sprite is heading to is still offset. Everything is fine on scale 1.

 

 

Yes! Got it working properly. You have to set camera scale to 1/scale not the input.

Edit. It doesn't work when changing the position of the camera. The problem is still there.

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

  • Recently Browsing   0 members

    No registered users viewing this page.