totallybueno Posted September 30, 2014 Report Share Posted September 30, 2014 Hi there, I´m having some problems with this, I have a basic system for my game, I need to check if the player clicked or touched the left or the right part of the screen, just that. It´s working perfectly on desktop but it´s not working with the game scaled and with cocoonJS, I guess I´m missing something. This is my code, can someone help telling me how to detect that "center point" in a scaled game? myFunction:function(click){ var clickX = click.clientX; if(this.world.width > this.scale.width){ var ratio = this.world.width/this.scale.width; clickX = Math.round(clickX/ratio); } if(clickX < this.scale.width*0.5){ //stuff to do if you touched the left part }else{ //stuff to do if you touched the right part } },Thanks in advance folks Quote Link to comment Share on other sites More sharing options...
j0hnskot Posted September 30, 2014 Report Share Posted September 30, 2014 I guess 'this' refers to the game object. Can you try using 'this.world.centerX'? For example : if(clickX<=this.world.centerX){ //clicked left part}else{ //clicked right part}Edit: Do you use the inputManager of phaser to get the value of X? or the browser's? Quote Link to comment Share on other sites More sharing options...
totallybueno Posted October 1, 2014 Author Report Share Posted October 1, 2014 Hi, thanks for the anwser. Well, the world is changing the size if the game is rescaled? It seems to be exactly the same size always (so world.centerX is always giving me the same number). Also, yep, I´m usin the inputManager to get that values: this.game.debug.inputInfo(click.clientX, click.clientY); Quote Link to comment Share on other sites More sharing options...
j0hnskot Posted October 1, 2014 Report Share Posted October 1, 2014 I dont think the size of the world gets changed. That's why it confuses me. If you use :this.game.input.activePointer.x; this.game.input.activePointer.y; the positions returned should be where the mouse is based on the world, regardless of the scale. How do you assign the x,y values on the "click" object? Quote Link to comment Share on other sites More sharing options...
totallybueno Posted October 6, 2014 Author Report Share Posted October 6, 2014 This last answer was the good one It´s working perfectly now, thanks j0hnskot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.