i_want_to_make_games Posted February 9, 2014 Share Posted February 9, 2014 How to detect if the mouse was clicked on the right or left side of the game? If it was clicked in pixel_x < game.width / 2 then I want to call func1(), and func2() otherwise. How can I do that? I've made working just arrow at the moment. Also, will I be able to convert it to android app after I finish? Will it understand that mouse click is the same as click on the screen? Link to comment Share on other sites More sharing options...
toto88x Posted February 9, 2014 Share Posted February 9, 2014 Something like this should work in your update() functionif (game.input.activePointer.x > game.width/2) right_side_click();else left_side_click(); Link to comment Share on other sites More sharing options...
XekeDeath Posted February 9, 2014 Share Posted February 9, 2014 What you want to do is attach a callback to the onDown event of the games input object.game.input.onDown.add(callbackFunction, this);Then, every time your player taps the screen, or clicks a mouse button, the callbackFunction is called, and will have the pointer object passed to it. This pointer object will have the x/y coordinates of the event in it. There are various x/ys to choose from, see here: http://docs.phaser.io/Phaser.Pointer.htmlcallbackFunction = function(pointer){ //Check where it happened and call function from here...} plicatibu 1 Link to comment Share on other sites More sharing options...
i_want_to_make_games Posted February 9, 2014 Author Share Posted February 9, 2014 Thank you so much guys. I am using if (game.input.mousePointer.isDown) and if (game.input.mousePointer.clientX > game.world.width / 2) and it seems to work nice. What about the other question: if I compile the game with cocoonjs, will it work on the android app? Will it understand that mouse click is the click on the screen? Also, I have fixed size pixels on the game, will it scale to fit the screen? Thanks again! Link to comment Share on other sites More sharing options...
XekeDeath Posted February 9, 2014 Share Posted February 9, 2014 If you are not using callbacks, and don't mind your func1() and func2() potentially being called multiple times in an update loop, then use game.input.activePointer instead of game.input.mousePointer, because it will be referring to the last active pointer, whether it be a touch or a click. Link to comment Share on other sites More sharing options...
i_want_to_make_games Posted February 9, 2014 Author Share Posted February 9, 2014 If you are not using callbacks, and don't mind your func1() and func2() potentially being called multiple times in an update loop, then use game.input.activePointer instead of game.input.mousePointer, because it will be referring to the last active pointer, whether it be a touch or a click.Thank you! But what about the other questions? Do you maybe know the answer? Thanks! Link to comment Share on other sites More sharing options...
i_want_to_make_games Posted February 9, 2014 Author Share Posted February 9, 2014 I've just tried using cocoojs and it doesn't recognise when I click the screen with my finger Link to comment Share on other sites More sharing options...
i_want_to_make_games Posted February 9, 2014 Author Share Posted February 9, 2014 No, it actually works! Great. It's just slow for some reason And I have black background where my there text should be. Link to comment Share on other sites More sharing options...
rich Posted February 9, 2014 Share Posted February 9, 2014 Use activePointer not mousePointer and I put it in a callback like Xeke said, otherwise it won't know about the click state until the next update loop. Link to comment Share on other sites More sharing options...
Recommended Posts