gamemaker touch controller spawn joystick where you touch

Y

ymmij12

Guest
I want to create a touch controller to spawn a joystick where you touch the screen and then destroy it when you don't touch the screen and to be invisible. Someone who knows how to build it?


Have this standard programming:
Object properties: obj_controller
Events: Create, initialize virtual key :

/// initialize virtual keys
// localvars
var width = sprite_get_width(spr_dpad);
var height = sprite_get_height(spr_dpad);

//dpad coordinates
dpad_x = 128;
dpad_y = display_get_gui_height()-height-128;

margin = 256;

var xx = dpad_x - margin;
var yy = dpad_y - margin;

global.vkey_left = virtual_key_add(xx,yy,width/3+margin,height+2*margin,vk_left);
global.vkey_up = virtual_key_add(xx,yy,width+2*margin,height/3+margin,vk_up);
global.vkey_right = virtual_key_add(xx+margin+(width/3)*2,yy,width/3+margin,height+2*margin,vk_right);
global.vkey_down = virtual_key_add(xx,yy+margin+(height/3)*2,width+2*margin,height/3+margin,vk_down);

// show virtual keys (for debug)
//virtual_key_show(global.vkey_left);
//virtual_key_show(global.vkey_up);
//virtual_key_show(global.vkey_right);
//virtual_key_show(global.vkey_down);

///Orginal
/// initialize virtual keys
/*
// localvars
var width = sprite_get_width(spr_dpad);
var height = sprite_get_height(spr_dpad);

//dpad coordinates
dpad_x = 16;
dpad_y = display_get_gui_height()-height-16;


margin = 128;

var xx = dpad_x - margin;
var yy = dpad_y - margin;

global.vkey_left = virtual_key_add(xx,yy,width/3+margin,height+2*margin,vk_left);
global.vkey_up = virtual_key_add(xx,yy,width+2*margin,height/3+margin,vk_up);
global.vkey_right = virtual_key_add(xx+margin+(width/3)*2,yy,width/3+margin,height+2*margin,vk_right);
global.vkey_down = virtual_key_add(xx,yy+margin+(height/3)*2,width+2*margin,height/3+margin,vk_down);

// show virtual keys (for debug)
//virtual_key_show(global.vkey_left);
//virtual_key_show(global.vkey_up);
//virtual_key_show(global.vkey_right);
//virtual_key_show(global.vkey_down);
*/


And in events
Draw GUI

/// draw dpad

draw_sprite_ext(spr_dpad,0,dpad_x,dpad_y,1,1,0,c_white,0.5);

Don't get the code to work whitout to draw GUI:(
 
Top