Jump to content


Photo

Multitouch Extension


  • Please log in to reply
12 replies to this topic

#1 connorcarpenter

connorcarpenter

    GMC Member

  • GMC Member
  • 6 posts

Posted 05 November 2011 - 04:28 AM

Download Extension Here
Multitouch Extension Download

I'm hoping others can extend this to make some functions for swipe, pinch, button, and joystick actions. So here's the code! It's simple! Good luck!

function touchInit(argument0){
    this.canvas = document.getElementById('canvas');
    window.touches = [];
    this.canvas.addEventListener('touchstart', function(event) {
      window.touches = event.touches;
    }, false);
    this.canvas.addEventListener('touchend', function(event) {
      window.touches = event.touches;
    }, false);
}

function touchNumber(){
    return window.touches.length;
}

function touchX(argument0){
    return (window.touches[argument0]).clientX;
}
function touchY(argument0){
    return (window.touches[argument0]).clientY;
}

I made this extension following the instructions in this article: Developing for Multi-touch Article

Instructions:

touchInit() - Call this at the beginning of your game.
touchNumber() - Returns the number of fingers on the mobile device screen.
touchX(touchIndex) - Returns the X value of the touch with ID touchIndex. touchIndex starts at 0 and goes up to touchNumber().
touchX(touchIndex) - Returns the Y value of the touch with ID touchIndex.

Yeah, so I didn't know how to do anything in Javascript or with canvas or with multi-touch stuff about 6 hours ago. I got so frustrated that I couldn't do multi-touch in my mobile game that I just looked it up on the net and did it myself.
For someone that KNEW how to program in Javascript, this would have taken 15 minutes. The Virtual Keys in the YoYoGames functions DO NOT SUPPORT MULTITOUCH (on iOS5 at least).
I just want to know why the YoYo team hasn't gotten here first and written 20 lines of code to help us utilize these features. Mobile games look and feel broken without multitouch capabilities that have become the mobile game standard.
Come on YoYoGames, it woulda been so easy to include the above functions, and they really make a big difference. Hope you can create these functions in the next release.

Anyway, you'll have to write your own functions to make it easier to make your own buttons/joysticks ect. to utilize these functions, but it should be fairly straightforward.

Good luck guys!

Edited by connorcarpenter, 05 November 2011 - 04:31 AM.

  • 1

#2 PrinceOfSorrow

PrinceOfSorrow

    GMC Member

  • GMC Member
  • 163 posts

Posted 05 January 2012 - 04:15 AM

Thank you so much for this extension , I was very disappointed when my platform game didn't work well on my Android device
due to multi touch issue :(

touchInit() - Call this at the beginning of your game.
touchNumber() - Returns the number of fingers on the mobile device screen.
touchX(touchIndex) - Returns the X value of the touch with ID touchIndex. touchIndex starts at 0 and goes up to touchNumber().
touchX(touchIndex) - Returns the Y value of the touch with ID touchIndex.


sorry to ask this, but could you at list show me an example code for touchX(touchIndex) and touchY(touchIndex) ? or how I define the touchNumber() ? in GML, does even your extension working with the mouse in case for test ? uploading an example will be very useful if you could.

again , I really appreciate your support for this issue :happy: .
  • 0

#3 connorcarpenter

connorcarpenter

    GMC Member

  • GMC Member
  • 6 posts

Posted 05 January 2012 - 10:32 AM

Yeah, I wish someone else could get rolling on some other functions using this extension, because it's got all you need for swipe, multi-finger swipe, button, and pinch controls.

Here's an example for a virtual button (that will actually work on iOS devices):

In creation event of a controller object:
touchInit();   ///starts watching for fingers touching the screen

In step event of button:
var i,a,b;
for(i=0;i<touchNumber();i+=1){     ///runs through every finger touching the screen
 a=touchX(i);  ///gets the X coordinate of finger i
 b=touchY(i);  //gets the Y coordinate of finger i
 
 if(a>LEFT && a<RIGHT && b>TOP && b<BOTTOM){ //// LEFT, RIGHT, TOP, and BOTTOM should define the area of the button on the screen
 
      ///Now do whatever action you want this button to do!
 
 }
 }


These functions are just for the touch screen, so you'll have to code seperately for the mouse.
Hope you got the jist of it. Good luck!
  • 1

#4 ObsidianNovels

ObsidianNovels

    GMC Member

  • GMC Member
  • 572 posts
  • Version:GM:HTML5

Posted 10 January 2012 - 09:01 PM

All buttons must be in one object, no? I tried creating an object for each button, but it didn't work on iPad/iPhone.
  • 1

#5 famous

famous

    GMC Member

  • GMC Member
  • 170 posts
  • Version:Unknown

Posted 08 June 2012 - 08:38 PM

Because it's an iPad/iPhone. :laugh:
  • -4

#6 Terrified Virus

Terrified Virus

    Moderators Plaything

  • GMC Member
  • 753 posts
  • Version:GM:Studio

Posted 08 July 2012 - 08:28 PM

This seems awesome, I will use it.
  • 0

#7 creativebunch

creativebunch

    The Bunchiest

  • GMC Member
  • 895 posts
  • Version:GM:Studio

Posted 09 July 2012 - 09:49 AM

This is awesome, and it works perfectly for me.
  • 0

#8 Terrified Virus

Terrified Virus

    Moderators Plaything

  • GMC Member
  • 753 posts
  • Version:GM:Studio

Posted 09 July 2012 - 04:56 PM

Wait... It was working perfect, but then it just messed up and now the buttons don't work anymore... What the heck?

EDIT:

I found the problem, but can't seem to fix it. It seems that the touch sense is off, by about 50 pixels, which is a lot to be off by. I have no idea why, any ideas?

Edited by Terrified Virus, 10 July 2012 - 03:38 AM.

  • 0

#9 creativebunch

creativebunch

    The Bunchiest

  • GMC Member
  • 895 posts
  • Version:GM:Studio

Posted 10 July 2012 - 02:57 PM

I found the problem, but can't seem to fix it. It seems that the touch sense is off, by about 50 pixels, which is a lot to be off by. I have no idea why, any ideas?

I think I know what you mean, if it's the same problem I found then there's a simple solution. Just subtract the window position from the touch position:
touchX(ind) - window_get_x()
touchY(ind) - window_get_y()

  • 0

#10 Terrified Virus

Terrified Virus

    Moderators Plaything

  • GMC Member
  • 753 posts
  • Version:GM:Studio

Posted 11 July 2012 - 04:18 AM


I found the problem, but can't seem to fix it. It seems that the touch sense is off, by about 50 pixels, which is a lot to be off by. I have no idea why, any ideas?

I think I know what you mean, if it's the same problem I found then there's a simple solution. Just subtract the window position from the touch position:
touchX(ind) - window_get_x()
touchY(ind) - window_get_y()

Hmmm... That could work, I will try.
  • 0

#11 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 14 February 2013 - 02:00 AM

So does this actually work perfectly, or not?
  • 0

#12 Zapchu25

Zapchu25

    GMC Member

  • GMC Member
  • 21 posts
  • Version:Unknown

Posted 01 March 2013 - 11:20 PM

Does this work for Windows 7 touch devices?
  • 0

#13 RBFraphael

RBFraphael

    GMC Member

  • New Member
  • 7 posts
  • Version:GM:Studio

Posted 27 May 2013 - 12:13 AM

please send a .GMZ example file :thumbsup:


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users