Jump to content

How to detect the center in a scaled game


totallybueno
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...