Jump to content

How to detect the center in a scaled game


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

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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