Jump to content


Photo

virtual keys not working on touchscreen


  • Please log in to reply
10 replies to this topic

#1 peter879

peter879

    GMC Member

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

Posted 03 May 2012 - 12:44 PM

I am new to GML, using Gamemaker HTML5.

I found code online for creating virtual keys.

My main object moves up, down, left, right using arrow keys in its keyboard events.

I made an invisible object with this codes:

step event:

global.vkup = YoYo_AddVirtualKey(400, view_yview+320, 64, 64, vk_up );
YoYo_ShowVirtualKey( global.vkup );

global.vkright = YoYo_AddVirtualKey( 464, view_yview+340, 64, 64, vk_right );
YoYo_ShowVirtualKey( global.vkright );

global.vkdown = YoYo_AddVirtualKey( 400, view_yview+364, 64, 64, vk_down );
YoYo_ShowVirtualKey( global.vkdown );

global.vkleft = YoYo_AddVirtualKey( 336, view_yview+340, 64, 64, vk_left );
YoYo_ShowVirtualKey( global.vkleft );

Draw event:

draw_sprite(spr_Up,-1,400, view_yview+320);
draw_sprite(spr_Right,-1,464, view_yview+340);
draw_sprite(spr_Down,-1,400, view_yview+364);
draw_sprite(spr_Left,-1,336, view_yview+340);

The problem is that the arrows appear on screen, but touching them has no effect.

I have struggled with this problem for a whole week.

Thank you.

NB: I asked this question in the html forum but got no reply. Don’t know how to remove the topic from there to avoid double post.
  • 0

#2 annihilator127

annihilator127

    GMC Member

  • GMC Member
  • 143 posts
  • Version:GM8

Posted 03 May 2012 - 12:55 PM

Does it work if you click the virtual keys with a mouse?
Some touch screens don't send a click when you tap the screen; you have to double-tap or press a button.
  • 0

#3 peter879

peter879

    GMC Member

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

Posted 03 May 2012 - 03:29 PM

Does it work if you click the virtual keys with a mouse?
Some touch screens don't send a click when you tap the screen; you have to double-tap or press a button.

Thank you for your reply.
No reaction to mouse either. I think something wrong with the code but can't figure what. Any ideas?
  • 0

#4 peter879

peter879

    GMC Member

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

Posted 04 May 2012 - 01:13 PM

Does it work if you click the virtual keys with a mouse?
Some touch screens don't send a click when you tap the screen; you have to double-tap or press a button.


I have included a link to the file here.

Someone out there who can make the virtual keys work?

Thanks!
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16810 posts
  • Version:GM:Studio

Posted 04 May 2012 - 01:19 PM

the virtual keys are defined as having an absolute position on the SCREEN not in the view. So, if your viewport is, for example, 640*480, then you should defien your virtual keys as being within that area, NOT using the relative coordinates as you are using just now. So, your code should probably be :



global.vkup = YoYo_AddVirtualKey(400, 320, 64, 64, vk_up );
global.vkright = YoYo_AddVirtualKey( 464, 340, 64, 64, vk_right );
global.vkdown = YoYo_AddVirtualKey( 400, 364, 64, 64, vk_down );
global.vkleft = YoYo_AddVirtualKey( 336, 340, 64, 64, vk_left );


  • 2

#6 peter879

peter879

    GMC Member

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

Posted 04 May 2012 - 06:56 PM

the virtual keys are defined as having an absolute position on the SCREEN not in the view. So, if your viewport is, for example, 640*480, then you should defien your virtual keys as being within that area, NOT using the relative coordinates as you are using just now. So, your code should probably be :



global.vkup = YoYo_AddVirtualKey(400, 320, 64, 64, vk_up );
global.vkright = YoYo_AddVirtualKey( 464, 340, 64, 64, vk_right );
global.vkdown = YoYo_AddVirtualKey( 400, 364, 64, 64, vk_down );
global.vkleft = YoYo_AddVirtualKey( 336, 340, 64, 64, vk_left );


It works now. Your explanation has solved my problem.

Thank you.

You deserve +5.
  • 0

#7 Javex

Javex

    GMC Member

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

Posted 03 July 2012 - 05:53 PM

hi, i'm with a problem with that


i used the same code, but, the buttons not show with a moviment of the views...
they are static :(
  • 0

#8 peter879

peter879

    GMC Member

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

Posted 28 November 2012 - 07:03 AM

hi, i'm with a problem with that


i used the same code, but, the buttons not show with a moviment of the views...
they are static :(

I think the drawing part of the keys needs to be written differently.

ie: virtual key: global.vkup = YoYo_AddVirtualKey(400, 320, 64, 64, vk_up );

draw: draw_sprite(spr_Up,-1,400, view_yview+320);
  • 0

#9 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16810 posts
  • Version:GM:Studio

Posted 28 November 2012 - 07:13 AM

No that's not it. They need to be drawn in the Draw GUI event with an ABSOLUTE value. They are no longer relative to the view, but rather static based on the screen/canvas size.

PS: This functionaility has changed since the topic was made!!!
  • 0

#10 peter879

peter879

    GMC Member

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

Posted 28 November 2012 - 07:32 AM

No that's not it. They need to be drawn in the Draw GUI event with an ABSOLUTE value. They are no longer relative to the view, but rather static based on the screen/canvas size.

PS: This functionaility has changed since the topic was made!!!

Oh, didn't know that!
Because i haven't worked with views for quite some time, but when i did some months ago, it worked fine.
  • 0

#11 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16810 posts
  • Version:GM:Studio

Posted 28 November 2012 - 07:36 AM

It would... But the last GM:S update has now removed the vk functions from the relative positioning in a room and made them have an absolute screen position based on the GUI size (as used by the draw gui event). You can find more information here: http://gmc.yoyogames...howtopic=561373
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users