• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Mobile Click/Touch Event Listener?

Explorer ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

Hello,

I have been trying to get my game to work on both a PC browser and mobile device. My game simply involves the user clicking the screen if the gameobject is within range of its target,  quite simple. However I have noticed when I click with the mouse or press with a mobile device the action only registers when i release/stop touching the mobile screen, this is very detrimental to the game as you have to be rather fast to hit an object.

Currently I have:

this.screen_hs.addEventListener("click", fl_MouseClickHandler2.bind(this));

function fl_MouseClickHandler2() {

     //do action

}

For the mobile interaction i have tried the following with no luck:

createjs.Touch.enable(stage);

this.screen_hs.addEventListener("touchstart", f2_MouseClickHandler.bind(this));

function f2_MouseClickHandler(){

     //do action

}

This code does absolutely nothing!

I was convinced this was the way forward however nothing seems to be working, can anyone point me in the right direction please?!

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 06, 2019 Aug 06, 2019

Oh I see.

So use the "mousedown" event instead.

Please let me know if it works now.

Votes

Translate

Translate
Community Expert ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

Hi.

You can keep the event as click. No need to use touchstart. Mouse events like click will be recognized even in touch devices.

function f2_MouseClickHandler()

{

    // do action

}

createjs.Touch.enable(stage);

this.screen_hs.addEventListener("click", f2_MouseClickHandler.bind(this));

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

Hey

Thanks for the help. I have tried this solution however I still have the issue with the function being executed on mouse up or 'touch up' on my mobile device?

I am trying to get this to work as soon as the mouse is clicked or on a mobile device when the screen is pressed?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

Oh I see.

So use the "mousedown" event instead.

Please let me know if it works now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

Thanks my friend you have helped me yet again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 06, 2019 Aug 06, 2019

Copy link to clipboard

Copied

LATEST

Excellent! You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines